init_priority and initialization of POD types
Wed Aug 12 18:19:00 GMT 2015
I'm tracking down some Valgrind findings. I believe I am seeing the following:
bool g_flag = false;
SomeObject g_object1 __attribute__ ((init_priority(150)));
// Uses global flag from a.cpp, and SomeObject from b.cpp
When I run the program under Valgrind, I'm catching an uninitialized
finding related to the global flag from a.cpp when g_object2 is used.
According to the man page on init_priority
In Standard C++, objects defined at namespace scope are guaranteed
to be initialized in an order in strict accordance with that of their
definitions in a given translation unit. No guarantee is made for
initializations across translation units. However, GNU C++ allows users
to control the order of initialization of objects defined at namespace scope
with the init_priority attribute by specifying a relative
priority, a constant
integral expression currently bounded between 101 and 65535 inclusive.
Lower numbers indicate a higher priority.
I assumed the object initialization came after POD initialization in a
translation unit, but it appears I am wrong. In fact, the man page
does not discuss the scenario.
What is the relationship among C++ objects with an init_priority
attribute and other POD types across translation units?
Thanks in advance.
More information about the Gcc-help