1 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -DGNU
2 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DGNU -std=c++98
3 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -std=c11 -DC11 -D__thread=_Thread_local
4 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++98
5 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DCXX11 -D__thread=thread_local -std=c++11 -Wno-deprecated
6 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++11 -Wno-deprecated
7 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic %s -std=c99 -D__thread=_Thread_local -DC99
10 // In C++, we define __private_extern__ to extern.
11 #undef __private_extern__
14 __thread
int t1
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
15 __thread
extern int t2
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
16 __thread
static int t3
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
18 // expected-warning@-3 {{'__thread' before 'extern'}}
19 // expected-warning@-3 {{'__thread' before 'static'}}
22 __thread __private_extern__
int t4
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
23 struct t5
{ __thread
int x
; }; // thread-local-warning {{'_Thread_local' is a C11 extension}}
25 // expected-error-re@-2 {{'{{__thread|_Thread_local|thread_local}}' is only allowed on variable declarations}}
27 // FIXME: The 'is only allowed on variable declarations' diagnostic is better here.
28 // expected-error@-5 {{type name does not allow storage class to be specified}}
31 __thread
int t6(void); // thread-local-warning {{'_Thread_local' is a C11 extension}}
33 // expected-error@-2 {{'__thread' is only allowed on variable declarations}}
34 #elif defined(C11) || defined(C99)
35 // expected-error@-4 {{'_Thread_local' is only allowed on variable declarations}}
37 // expected-error@-6 {{'thread_local' is only allowed on variable declarations}}
40 int f(__thread
int t7
) { // expected-error {{' is only allowed on variable declarations}} \
41 // thread-local-warning {{'_Thread_local' is a C11 extension}}
42 __thread
int t8
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
44 // expected-error@-2 {{'__thread' variables must have global storage}}
45 #elif defined(C11) || defined(C99)
46 // expected-error@-4 {{'_Thread_local' variables must have global storage}}
48 extern __thread
int t9
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
49 static __thread
int t10
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
50 __thread __private_extern__
int t11
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
51 #if __cplusplus < 201103L
52 __thread
auto int t12a
; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local}}' declaration specifier}} \
53 // thread-local-warning {{'_Thread_local' is a C11 extension}}
54 auto __thread
int t12b
; // expected-error {{cannot combine with previous 'auto' declaration specifier}} \
55 // thread-local-warning {{'_Thread_local' is a C11 extension}}
57 __thread
auto t12a
= 0; // expected-error {{'_Thread_local' variables must have global storage}} \
58 // thread-local-warning {{'_Thread_local' is a C11 extension}}
59 auto __thread t12b
= 0; // expected-error {{'_Thread_local' variables must have global storage}} \
60 // thread-local-warning {{'_Thread_local' is a C11 extension}}
62 __thread
register int t13a
; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
63 // thread-local-warning {{'_Thread_local' is a C11 extension}}
64 register __thread
int t13b
; // expected-error {{cannot combine with previous 'register' declaration specifier}} \
65 // thread-local-warning {{'_Thread_local' is a C11 extension}}
68 __thread
typedef int t14
; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
69 // thread-local-warning {{'_Thread_local' is a C11 extension}}
70 __thread
int t15
; // expected-note {{previous definition is here}} \
71 // thread-local-warning {{'_Thread_local' is a C11 extension}}
72 extern int t15
; // expected-error {{non-thread-local declaration of 't15' follows thread-local declaration}}
73 extern int t16
; // expected-note {{previous declaration is here}}
74 __thread
int t16
; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}} \
75 // thread-local-warning {{'_Thread_local' is a C11 extension}}
78 extern thread_local
int t17
; // expected-note {{previous declaration is here}}
79 _Thread_local
int t17
; // expected-error {{thread-local declaration of 't17' with static initialization follows declaration with dynamic initialization}} \
80 // expected-warning {{'_Thread_local' is a C11 extension}}
81 extern _Thread_local
int t18
; // expected-note {{previous declaration is here}} \
82 // expected-warning {{'_Thread_local' is a C11 extension}}
83 thread_local
int t18
; // expected-error {{thread-local declaration of 't18' with dynamic initialization follows declaration with static initialization}}
87 __thread
int thread_int
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
88 int *thread_int_ptr
= &thread_int
;
90 // expected-error@-2 {{initializer element is not a compile-time constant}}
93 int *p
= &thread_int
; // This is perfectly fine, though.
95 #if __cplusplus >= 201103L
96 constexpr int *thread_int_ptr_2
= &thread_int
; // expected-error {{must be initialized by a constant expression}}
100 __thread
int non_const_init
= non_const(); // thread-local-warning {{'_Thread_local' is a C11 extension}}
101 #if !defined(__cplusplus)
102 // expected-error@-2 {{initializer element is not a compile-time constant}}
103 #elif !defined(CXX11)
104 // expected-error@-4 {{initializer for thread-local variable must be a constant expression}}
105 #if __cplusplus >= 201103L
106 // expected-note@-6 {{use 'thread_local' to allow this}}
114 __thread S s
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
116 // expected-error@-2 {{type of thread-local variable has non-trivial destruction}}
117 #if __cplusplus >= 201103L
118 // expected-note@-4 {{use 'thread_local' to allow this}}
127 __thread HasCtor var_with_ctor
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
129 // expected-error@-2 {{initializer for thread-local variable must be a constant expression}}
130 #if __cplusplus >= 201103L
131 // expected-note@-4 {{use 'thread_local' to allow this}}
136 __thread
int aggregate
[10] = {0}; // thread-local-warning {{'_Thread_local' is a C11 extension}}