non-deferred static member initialization for templates in gcc?

前端 未结 2 1311
醉梦人生
醉梦人生 2021-02-05 22:04

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

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 22:31

    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.

提交回复
热议问题