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
9 __thread
int t1
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
10 __thread
extern int t2
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
11 __thread
static int t3
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
13 // expected-warning@-3 {{'__thread' before 'extern'}}
14 // expected-warning@-3 {{'__thread' before 'static'}}
17 __private_extern__ __thread
int t4
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
18 struct t5
{ __thread
int x
; }; // thread-local-warning {{'_Thread_local' is a C11 extension}}
20 // expected-error-re@-2 {{'{{__thread|_Thread_local|thread_local}}' is only allowed on variable declarations}}
22 // FIXME: The 'is only allowed on variable declarations' diagnostic is better here.
23 // expected-error@-5 {{type name does not allow storage class to be specified}}
26 __thread
int t6(void); // thread-local-warning {{'_Thread_local' is a C11 extension}}
28 // expected-error@-2 {{'__thread' is only allowed on variable declarations}}
29 #elif defined(C11) || defined(C99)
30 // expected-error@-4 {{'_Thread_local' is only allowed on variable declarations}}
32 // expected-error@-6 {{'thread_local' is only allowed on variable declarations}}
35 int f(__thread
int t7
) { // expected-error {{' is only allowed on variable declarations}} \
36 // thread-local-warning {{'_Thread_local' is a C11 extension}}
37 __thread
int t8
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
39 // expected-error@-2 {{'__thread' variables must have global storage}}
40 #elif defined(C11) || defined(C99)
41 // expected-error@-4 {{'_Thread_local' variables must have global storage}}
43 extern __thread
int t9
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
44 static __thread
int t10
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
45 __private_extern__ __thread
int t11
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
46 #if __cplusplus < 201103L
47 __thread
auto int t12a
; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local}}' declaration specifier}} \
48 // thread-local-warning {{'_Thread_local' is a C11 extension}}
49 auto __thread
int t12b
; // expected-error {{cannot combine with previous 'auto' declaration specifier}} \
50 // thread-local-warning {{'_Thread_local' is a C11 extension}}
52 __thread
auto t12a
= 0; // expected-error {{'_Thread_local' variables must have global storage}} \
53 // thread-local-warning {{'_Thread_local' is a C11 extension}}
54 auto __thread t12b
= 0; // expected-error {{'_Thread_local' variables must have global storage}} \
55 // thread-local-warning {{'_Thread_local' is a C11 extension}}
57 __thread
register int t13a
; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
58 // thread-local-warning {{'_Thread_local' is a C11 extension}}
59 register __thread
int t13b
; // expected-error {{cannot combine with previous 'register' declaration specifier}} \
60 // thread-local-warning {{'_Thread_local' is a C11 extension}}
63 __thread
typedef int t14
; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
64 // thread-local-warning {{'_Thread_local' is a C11 extension}}
65 __thread
int t15
; // expected-note {{previous definition is here}} \
66 // thread-local-warning {{'_Thread_local' is a C11 extension}}
67 extern int t15
; // expected-error {{non-thread-local declaration of 't15' follows thread-local declaration}}
68 extern int t16
; // expected-note {{previous declaration is here}}
69 __thread
int t16
; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}} \
70 // thread-local-warning {{'_Thread_local' is a C11 extension}}
73 extern thread_local
int t17
; // expected-note {{previous declaration is here}}
74 _Thread_local
int t17
; // expected-error {{thread-local declaration of 't17' with static initialization follows declaration with dynamic initialization}} \
75 // expected-warning {{'_Thread_local' is a C11 extension}}
76 extern _Thread_local
int t18
; // expected-note {{previous declaration is here}} \
77 // expected-warning {{'_Thread_local' is a C11 extension}}
78 thread_local
int t18
; // expected-error {{thread-local declaration of 't18' with dynamic initialization follows declaration with static initialization}}
82 __thread
int thread_int
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
83 int *thread_int_ptr
= &thread_int
;
85 // expected-error@-2 {{initializer element is not a compile-time constant}}
88 int *p
= &thread_int
; // This is perfectly fine, though.
90 #if __cplusplus >= 201103L
91 constexpr int *thread_int_ptr_2
= &thread_int
; // expected-error {{must be initialized by a constant expression}}
95 __thread
int non_const_init
= non_const(); // thread-local-warning {{'_Thread_local' is a C11 extension}}
96 #if !defined(__cplusplus)
97 // expected-error@-2 {{initializer element is not a compile-time constant}}
99 // expected-error@-4 {{initializer for thread-local variable must be a constant expression}}
100 #if __cplusplus >= 201103L
101 // expected-note@-6 {{use 'thread_local' to allow this}}
109 __thread S s
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
111 // expected-error@-2 {{type of thread-local variable has non-trivial destruction}}
112 #if __cplusplus >= 201103L
113 // expected-note@-4 {{use 'thread_local' to allow this}}
122 __thread HasCtor var_with_ctor
; // thread-local-warning {{'_Thread_local' is a C11 extension}}
124 // expected-error@-2 {{initializer for thread-local variable must be a constant expression}}
125 #if __cplusplus >= 201103L
126 // expected-note@-4 {{use 'thread_local' to allow this}}
131 __thread
int aggregate
[10] = {0}; // thread-local-warning {{'_Thread_local' is a C11 extension}}