[LLVMbugs] [Bug 21690] New: static __thread T* ptr(0); error: initializer for thread-local variable must be a constant expression (while T* ptr = 0 will work)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Nov 29 06:29:57 PST 2014


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

            Bug ID: 21690
           Summary: static __thread T* ptr(0); error: initializer for
                    thread-local variable must be a constant expression
                    (while T* ptr = 0 will work)
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david.abdurachmanov at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I bumped Clang to pre-3.6 (65d8b4c4998b3a0c20934ea72ede72ef4838a004, r222081,
~15 Nov). Have not checked the trunk version.

$ cat test.cc
template <typename T>
void dummy() {
 static __thread T* ptr(0);
}

$ clang++ -std=c++11 test.cc
test.cc:3:25: error: initializer for thread-local variable must be a constant
expression
 static __thread T* ptr(0);
                       ^~~
test.cc:3:22: note: use 'thread_local' to allow this
 static __thread T* ptr(0);
                    ^
1 error generated.

The following will work:

static __thread T* ptr;
static __thread T* ptr = 0;
static __thread T* ptr = nullptr;
static thread_local T* ptr(nullptr);

The following will not work:

static __thread T* ptr{0};
static __thread T* ptr(0);

It works with c-like initialization, but not with constructor initialization or
uniform initialization.

We are assigning initial value of pointer (nullptr), isn't nullptr/0 are
constant expression here?

-- 
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/20141129/b1fabc22/attachment.html>


More information about the llvm-bugs mailing list