[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Preprocessor / has_attribute.cpp
blobbf0f9b3bc4a8f085b3338d536a005dd27ffa0bda
1 // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM --implicit-check-not=:
2 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s -o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
4 #define CXX11(x) x: __has_cpp_attribute(x)
6 // CHECK: clang::fallthrough: 201603L
7 CXX11(clang::fallthrough)
9 // CHECK: selectany: 0
10 CXX11(selectany)
12 // The attribute name can be bracketed with double underscores.
13 // CHECK: clang::__fallthrough__: 201603L
14 CXX11(clang::__fallthrough__)
16 // The scope cannot be bracketed with double underscores unless it is
17 // for gnu or clang.
18 // CHECK: __gsl__::suppress: 0
19 CXX11(__gsl__::suppress)
21 // CHECK: _Clang::fallthrough: 201603L
22 CXX11(_Clang::fallthrough)
24 // CHECK: __nodiscard__: 201907L
25 CXX11(__nodiscard__)
27 // CHECK: __gnu__::__const__: 1
28 CXX11(__gnu__::__const__)
30 // Test that C++11, target-specific attributes behave properly.
32 // CHECK: gnu::mips16: 0
33 CXX11(gnu::mips16)
35 // Test for standard attributes as listed in C++2a [cpp.cond] paragraph 6.
37 CXX11(assert)
38 CXX11(carries_dependency)
39 CXX11(deprecated)
40 CXX11(ensures)
41 CXX11(expects)
42 CXX11(fallthrough)
43 CXX11(likely)
44 CXX11(maybe_unused)
45 CXX11(no_unique_address)
46 CXX11(nodiscard)
47 CXX11(noreturn)
48 CXX11(unlikely)
49 // FIXME(201806L) CHECK: assert: 0
50 // CHECK: carries_dependency: 200809L
51 // CHECK: deprecated: 201309L
52 // FIXME(201806L) CHECK: ensures: 0
53 // FIXME(201806L) CHECK: expects: 0
54 // CHECK: fallthrough: 201603L
55 // CHECK: likely: 201803L
56 // CHECK: maybe_unused: 201603L
57 // ITANIUM: no_unique_address: 201803L
58 // WINDOWS: no_unique_address: 0
59 // CHECK: nodiscard: 201907L
60 // CHECK: noreturn: 200809L
61 // CHECK: unlikely: 201803L
63 namespace PR48462 {
64 // Test that macro expansion of the builtin argument works.
65 #define C clang
66 #define F fallthrough
67 #define CF clang::fallthrough
69 #if __has_cpp_attribute(F)
70 int has_fallthrough;
71 #endif
72 // CHECK: int has_fallthrough;
74 #if __has_cpp_attribute(C::F)
75 int has_clang_falthrough_1;
76 #endif
77 // CHECK: int has_clang_falthrough_1;
79 #if __has_cpp_attribute(clang::F)
80 int has_clang_falthrough_2;
81 #endif
82 // CHECK: int has_clang_falthrough_2;
84 #if __has_cpp_attribute(C::fallthrough)
85 int has_clang_falthrough_3;
86 #endif
87 // CHECK: int has_clang_falthrough_3;
89 #if __has_cpp_attribute(CF)
90 int has_clang_falthrough_4;
91 #endif
92 // CHECK: int has_clang_falthrough_4;
94 #define FUNCLIKE1(x) clang::x
95 #if __has_cpp_attribute(FUNCLIKE1(fallthrough))
96 int funclike_1;
97 #endif
98 // CHECK: int funclike_1;
100 #define FUNCLIKE2(x) _Clang::x
101 #if __has_cpp_attribute(FUNCLIKE2(fallthrough))
102 int funclike_2;
103 #endif
104 // CHECK: int funclike_2;
107 // Test for Microsoft __declspec attributes
109 #define DECLSPEC(x) x: __has_declspec_attribute(x)
111 // CHECK: uuid: 1
112 // CHECK: __uuid__: 1
113 DECLSPEC(uuid)
114 DECLSPEC(__uuid__)
116 // CHECK: fallthrough: 0
117 DECLSPEC(fallthrough)
119 namespace PR48462 {
120 // Test that macro expansion of the builtin argument works.
121 #define U uuid
123 #if __has_declspec_attribute(U)
124 int has_uuid;
125 #endif
126 // CHECK: int has_uuid;