The Some
constructor will be run on the first call to globalFunction()
. This is discussed in Scott Meyer's Effective C++, Item 4.
This is enforced by the standard.
Note, that there may still be a problem with the destructor! In general, it's not possible to know when it is safe to delete this object, another thread (maybe living past main) might call this function after the local static has been destroyed, for this reason, these objects are often 'leaked' by creating them with 'new'.
But, also note that creating static objects like this is not thread safe anyways.
Global static objects will be constructed before main, it an undefined order.