Clang Project

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