xref: /aosp_15_r20/external/clang/test/SemaCXX/declspec-thread.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -fms-extensions -fms-compatibility-version=18.00 -verify %s
2*67e74705SXin Li // RUN: %clang_cc1 -triple i686-pc-win32 -std=c++11 -fms-extensions -fms-compatibility-version=19.00 -verify %s
3*67e74705SXin Li 
4*67e74705SXin Li __thread __declspec(thread) int a; // expected-error {{already has a thread-local storage specifier}}
5*67e74705SXin Li __declspec(thread) __thread int b; // expected-error {{already has a thread-local storage specifier}}
6*67e74705SXin Li __declspec(thread) int c(); // expected-warning {{only applies to variables}}
7*67e74705SXin Li __declspec(thread) int d;
8*67e74705SXin Li int foo();
9*67e74705SXin Li #if _MSC_VER >= 1900
10*67e74705SXin Li __declspec(thread) int e = foo();
11*67e74705SXin Li #else
12*67e74705SXin Li __declspec(thread) int e = foo(); // expected-error {{must be a constant expression}} expected-note {{thread_local}}
13*67e74705SXin Li #endif
14*67e74705SXin Li 
15*67e74705SXin Li struct HasCtor { HasCtor(); int x; };
16*67e74705SXin Li #if _MSC_VER >= 1900
17*67e74705SXin Li __declspec(thread) HasCtor f;
18*67e74705SXin Li #else
19*67e74705SXin Li __declspec(thread) HasCtor f; // expected-error {{must be a constant expression}} expected-note {{thread_local}}
20*67e74705SXin Li #endif
21*67e74705SXin Li 
22*67e74705SXin Li struct HasDtor { ~HasDtor(); int x; };
23*67e74705SXin Li #if _MSC_VER >= 1900
24*67e74705SXin Li __declspec(thread) HasDtor g;
25*67e74705SXin Li #else
26*67e74705SXin Li __declspec(thread) HasCtor g; // expected-error {{must be a constant expression}} expected-note {{thread_local}}
27*67e74705SXin Li #endif
28*67e74705SXin Li 
29*67e74705SXin Li struct HasDefaultedDefaultCtor {
30*67e74705SXin Li   HasDefaultedDefaultCtor() = default;
31*67e74705SXin Li   int x;
32*67e74705SXin Li };
33*67e74705SXin Li __declspec(thread) HasDefaultedDefaultCtor h;
34*67e74705SXin Li 
35*67e74705SXin Li struct HasConstexprCtor {
HasConstexprCtorHasConstexprCtor36*67e74705SXin Li   constexpr HasConstexprCtor(int x) : x(x) {}
37*67e74705SXin Li   int x;
38*67e74705SXin Li };
39*67e74705SXin Li __declspec(thread) HasConstexprCtor i(42);
40*67e74705SXin Li 
foo()41*67e74705SXin Li int foo() {
42*67e74705SXin Li   __declspec(thread) int a; // expected-error {{must have global storage}}
43*67e74705SXin Li   static __declspec(thread) int b;
44*67e74705SXin Li }
45*67e74705SXin Li 
46*67e74705SXin Li extern __declspec(thread) int fwd_thread_var;
47*67e74705SXin Li __declspec(thread) int fwd_thread_var = 5;
48*67e74705SXin Li 
49*67e74705SXin Li extern int fwd_thread_var_mismatch; // expected-note {{previous declaration}}
50*67e74705SXin Li __declspec(thread) int fwd_thread_var_mismatch = 5; // expected-error-re {{thread-local {{.*}} follows non-thread-local}}
51*67e74705SXin Li 
52*67e74705SXin Li extern __declspec(thread) int thread_mismatch_2; // expected-note {{previous declaration}}
53*67e74705SXin Li int thread_mismatch_2 = 5; // expected-error-re {{non-thread-local {{.*}} follows thread-local}}
54*67e74705SXin Li 
55*67e74705SXin Li typedef __declspec(thread) int tls_int_t; // expected-warning {{only applies to variables}}
56