public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60673] New: c++11 static thread_local members may cause a segfault when accessed via 'this->'
@ 2014-03-26 16:47 michael at ensslin dot cc
  2014-03-26 18:44 ` [Bug c++/60673] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: michael at ensslin dot cc @ 2014-03-26 16:47 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-22 22:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-26 16:47 [Bug c++/60673] New: c++11 static thread_local members may cause a segfault when accessed via 'this->' michael at ensslin dot cc
2014-03-26 18:44 ` [Bug c++/60673] " redi at gcc dot gnu.org
2021-08-22 22:46 ` pinskia at gcc dot gnu.org
2021-08-22 22:48 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).