https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83568
Bug ID: 83568 Summary: thread_local class members not initialized before accessed using operator :: Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tinrow at gmail dot com Target Milestone: --- thread_local class members are not initialized as expected, if it is accessed using member access operator (dot) instead of scope resolution operator :: . The initialization only happens on the first time it is accessed using operator :: . reproducible code (gcc 4.8 - 7.1): #include <iostream> bool initialized = false; int init() { initialized = true; return 1; } struct A { static thread_local int foo; }; thread_local int A::foo { init() }; int main() { A a; std::cout << (initialized ? "ok" : "bug" ) << std::endl; std::cout << a.foo << std::endl; std::cout << A::foo << std::endl; return 0; } Output: bug 0 1