https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60702
Kan Wang <tinrow at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tinrow at gmail dot com --- Comment #5 from Kan Wang <tinrow at gmail dot com> --- +1 for this. If class member has thread-local storage and is first accessed through member access operator (e.g. a.foo), it is not initialized as expected. The short code snippet below reproduces the bug on g++ 4.8 - 7.1 #include <iostream> int init() { std::cout << "init" << std::endl; return 0; } struct A { static thread_local int foo; }; thread_local int A::foo { init() }; int main() { A a; int i = a.foo; std::cout << "--- should be initialized above ---" << std::endl; i = A::foo; return i; } Output: --- should be initialized above --- init