[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / declspec-thread.cpp
blob2b931bbde3e953ffa2de7cee8d695f5183fcfd96
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
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;
8 int 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
15 struct 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
22 struct 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
29 struct HasDefaultedDefaultCtor {
30 HasDefaultedDefaultCtor() = default;
31 int x;
33 __declspec(thread) HasDefaultedDefaultCtor h;
35 struct HasConstexprCtor {
36 constexpr HasConstexprCtor(int x) : x(x) {}
37 int x;
39 __declspec(thread) HasConstexprCtor i(42);
41 int foo() {
42 __declspec(thread) int a; // expected-error {{must have global storage}}
43 static __declspec(thread) int b;
46 extern __declspec(thread) int fwd_thread_var;
47 __declspec(thread) int fwd_thread_var = 5;
49 extern 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}}
52 extern __declspec(thread) int thread_mismatch_2; // expected-note {{previous declaration}}
53 int thread_mismatch_2 = 5; // expected-error-re {{non-thread-local {{.*}} follows thread-local}}
55 typedef __declspec(thread) int tls_int_t; // expected-warning {{only applies to variables}}