This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/83568] New: thread_local class members not initialized before accessed using operator ::
- From: "tinrow at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 24 Dec 2017 02:56:25 +0000
- Subject: [Bug c++/83568] New: thread_local class members not initialized before accessed using operator ::
- Auto-submitted: auto-generated
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