http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60673
Bug ID: 60673 Summary: c++11 static thread_local members may cause a segfault when accessed via 'this->' Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: michael at ensslin dot cc In the following minimal example, f() causes a segfault in the compiled program, while g() and h() don't. Note that the error also occurs in clang++. mic@mic-nb $ cat test.cpp #include <string> struct A{ static thread_local std::string s; void f() { this->s = "segv"; } void g() { A::s = "no segv"; } void h() { s = "no segv"; } }; thread_local std::string A::s; int main() { A{}.f(); return 0; } mic@mic-nb $ g++ -std=c++11 -lpthread test.cpp mic@mic-nb $ ./a.out [1] 11729 segmentation fault (core dumped) ./a.out mic@mic-nb $ clang++ -std=c++11 -lpthread test.cpp mic@mic-nb $ ./a.out [1] 11764 segmentation fault (core dumped) ./a.out Precise versions of installed software: mic@mic-nb $ g++ --version g++ (GCC) 4.8.2 20140206 (prerelease) Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. mic@mic-nb $ clang++ --version clang version 3.4 (tags/RELEASE_34/final) Target: x86_64-unknown-linux-gnu Thread model: posix mic@mic-nb $ uname -a Linux mic-nb 3.13.6-1-ARCH #1 SMP PREEMPT Fri Mar 7 22:47:48 CET 2014 x86_64 GNU/Linux