"Parser allowed 'typedef' as storage class VarDecl.");
VarDecl::StorageClass SC = StorageClassSpecToVarDeclStorageClass(SCSpec);
- if (getLangOpts().OpenCL && !getOpenCLOptions().cl_khr_fp16)
- {
+ if (getLangOpts().OpenCL && !getOpenCLOptions().cl_khr_fp16) {
// OpenCL v1.2 s6.1.1.1: reject declaring variables of the half and
// half array type (unless the cl_khr_fp16 extension is enabled).
if (Context.getBaseElementType(R)->isHalfType()) {
SC = SC_None;
}
+ // C++11 [dcl.stc]p4:
+ // When thread_local is applied to a variable of block scope the
+ // storage-class-specifier static is implied if it does not appear
+ // explicitly.
+ // Core issue: 'static' is not implied if the variable is declared 'extern'.
+ if (SCSpec == DeclSpec::SCS_unspecified &&
+ D.getDeclSpec().getThreadStorageClassSpec() ==
+ DeclSpec::TSCS_thread_local && DC->isFunctionOrMethod())
+ SC = SC_Static;
+
IdentifierInfo *II = Name.getAsIdentifierInfo();
if (!II) {
Diag(D.getIdentifierLoc(), diag::err_bad_variable_name)
// expected-error@-2 {{'__thread' variables must have global storage}}
#elif defined(C11)
// expected-error@-4 {{'_Thread_local' variables must have global storage}}
-#else
- // expected-error@-6 {{'thread_local' variables must have global storage}}
#endif
extern __thread int t9;
static __thread int t10;
#if __cplusplus < 201103L
__thread auto int t12a; // expected-error-re {{cannot combine with previous '(__thread|_Thread_local)' declaration specifier}}
auto __thread int t12b; // expected-error {{cannot combine with previous 'auto' declaration specifier}}
-#else
- __thread auto t12a = 0; // expected-error-re {{'(t|_T)hread_local' variables must have global storage}}
- auto __thread t12b = 0; // expected-error-re {{'(t|_T)hread_local' variables must have global storage}}
+#elif !defined(CXX11)
+ __thread auto t12a = 0; // expected-error-re {{'_Thread_local' variables must have global storage}}
+ auto __thread t12b = 0; // expected-error-re {{'_Thread_local' variables must have global storage}}
#endif
__thread register int t13a; // expected-error-re {{cannot combine with previous '(__thread|_Thread_local|thread_local)' declaration specifier}}
register __thread int t13b; // expected-error {{cannot combine with previous 'register' declaration specifier}}
--- /dev/null
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+struct S {
+ static thread_local int a;
+ static int b; // expected-note {{here}}
+ thread_local int c; // expected-error {{'thread_local' is only allowed on variable declarations}}
+ static thread_local int d; // expected-note {{here}}
+};
+
+thread_local int S::a;
+thread_local int S::b; // expected-error {{thread-local declaration of 'b' follows non-thread-local declaration}}
+thread_local int S::c; // expected-error {{non-static data member defined out-of-line}}
+int S::d; // expected-error {{non-thread-local declaration of 'd' follows thread-local declaration}}
+
+thread_local int x[3];
+thread_local int y[3];
+thread_local int z[3]; // expected-note {{previous}}
+
+void f() {
+ thread_local int x;
+ static thread_local int y;
+ extern thread_local int z; // expected-error {{redefinition of 'z' with a different type}}
+}