Does gcc have any guarantees about static member initialization timing, especially regarding template classes?
I want to know if I can get a hard guarantee that static m
As you've already found out the C++ standard doesn't guarantee that "the dynamic initialization of a non-local variable with static storage duration is done before the first statement of main". However, GCC does peform such initialization before executing main as described in How Initialization Functions Are Handled.
The only problem is initialization of static objects from shared libraries loaded with dlopen
. These will only be initialized at the time the library is loaded, but there's nothing you can do about it.