[LLVMbugs] [Bug 19288] New: thread_local member variable accessed without being constructed

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Mar 30 21:32:30 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19288

            Bug ID: 19288
           Summary: thread_local member variable accessed without being
                    constructed
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arturomdn at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

This bug exists in both clang++ and g++ and was first reported in
stackoverflow:

http://stackoverflow.com/questions/22722941/thread-local-member-variable-construction

A simple test case is here

http://coliru.stacked-crooked.com/a/959f4c60a9f90116

    #include <iostream>
    using namespace std;
    struct foo {
        int i;
        foo(): i{42} {}
    };
    struct bar {
        static thread_local foo FOO;
    };
    thread_local foo bar::FOO;
    int main() {
        //cerr << string((bar::FOO.i == 42) ? "Ok" : "Bug") << endl; //Ok
        cerr << string((bar().FOO.i == 42) ? "Ok" : "Bug") << endl;  //Bug
        return 0;
    }

Invoked as

clang++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out

Output is
    Bug

Expected output is
    Ok

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140331/c5cc5a20/attachment.html>


More information about the llvm-bugs mailing list