https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89727

            Bug ID: 89727
           Summary: static thread_local ODR use broken
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: leppkes at stce dot rwth-aachen.de
  Target Milestone: ---

Created attachment 45972
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45972&action=edit
minimal example of incorrect behavior (static member B::a should be initialized
before first usage).

In the bug example, there are 3 uses of a static thread_local member. 
>From my understanding to the C++ Standard, the compiler should initialize the
member before first use (ODR Rule).

Clang and Intel C++ Compiler behave correct from my understanding. GNU C++
initializes too late.

~/gcc_bug$ g++ test.cpp; ./a.out 
0
constructing A.
42
42
~/gcc_bug$ icc test.cpp; ./a.out 
constructing A.
42
42
42
~/gcc_bug$ clang++ test.cpp; ./a.out 
constructing A.
42
42
42

Reply via email to