<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - c++11 static thread_local members may cause a segfault when accessed via 'this->'"
   href="http://llvm.org/bugs/show_bug.cgi?id=19254">19254</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>c++11 static thread_local members may cause a segfault when accessed via 'this->'
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>michael@ensslin.cc
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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 g++.

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</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>