[Bug c++/60702] thread_local initialization
dv.main at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 28 22:52:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60702
--- Comment #3 from Stan Pavlovski <dv.main at gmail dot com> ---
Template class' thread_local member is not initialized unless other
non-template class' thread_local member is initialized first:
#include <iostream>
using namespace std;
struct far {
struct boo {
boo () {
cerr << "far::boo" << endl;
}
int i = 42;
};
static void baz() {
cerr << far::FOO.i << endl;
}
static thread_local boo FOO;
};
template<class T>
struct bar {
struct foo {
foo () {
cerr << "bar::foo" << endl;
}
int i = 42;
};
void baz() {
cerr << bar::FOO.i << endl;
}
static thread_local foo FOO;
};
template<class T> thread_local typename bar<T>::foo bar<T>::FOO;
thread_local typename far::boo far::FOO;
int main() {
bar<int> b;
b.baz();
far f;
f.baz();
return 0;
}
Output:
0
far::boo
bar::foo
42
More information about the Gcc-bugs
mailing list