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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to