Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Preprocessor / has_attribute.cpp
blob33546dbb175f6175d1eaeb5150ca981f5ce14e4d
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: 1
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__: 1
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: 1
22 CXX11(_Clang::fallthrough)
24 // CHECK: __nodiscard__: 201907L
25 CXX11(__nodiscard__)
27 // CHECK: warn_unused_result: 0
28 CXX11(warn_unused_result)
30 // CHECK: gnu::warn_unused_result: 1
31 CXX11(gnu::warn_unused_result)
33 // CHECK: clang::warn_unused_result: 1
34 CXX11(clang::warn_unused_result)
36 // CHECK: __gnu__::__const__: 1
37 CXX11(__gnu__::__const__)
39 // Test that C++11, target-specific attributes behave properly.
41 // CHECK: gnu::mips16: 0
42 CXX11(gnu::mips16)
44 // Test for standard attributes as listed in C++2a [cpp.cond] paragraph 6.
46 CXX11(assert)
47 CXX11(carries_dependency)
48 CXX11(deprecated)
49 CXX11(ensures)
50 CXX11(expects)
51 CXX11(fallthrough)
52 CXX11(likely)
53 CXX11(maybe_unused)
54 CXX11(no_unique_address)
55 CXX11(msvc::no_unique_address)
56 CXX11(nodiscard)
57 CXX11(noreturn)
58 CXX11(unlikely)
59 // FIXME(201806L) CHECK: assert: 0
60 // CHECK: carries_dependency: 200809L
61 // CHECK: deprecated: 201309L
62 // FIXME(201806L) CHECK: ensures: 0
63 // FIXME(201806L) CHECK: expects: 0
64 // CHECK: fallthrough: 201603L
65 // CHECK: likely: 201803L
66 // CHECK: maybe_unused: 201603L
67 // ITANIUM: no_unique_address: 201803L
68 // WINDOWS: no_unique_address: 0
69 // ITANIUM: msvc::no_unique_address: 0
70 // WINDOWS: msvc::no_unique_address: 201803L
71 // CHECK: nodiscard: 201907L
72 // CHECK: noreturn: 200809L
73 // CHECK: unlikely: 201803L
75 namespace PR48462 {
76 // Test that macro expansion of the builtin argument works.
77 #define C clang
78 #define F fallthrough
79 #define CF clang::fallthrough
81 #if __has_cpp_attribute(F)
82 int has_fallthrough;
83 #endif
84 // CHECK: int has_fallthrough;
86 #if __has_cpp_attribute(C::F)
87 int has_clang_falthrough_1;
88 #endif
89 // CHECK: int has_clang_falthrough_1;
91 #if __has_cpp_attribute(clang::F)
92 int has_clang_falthrough_2;
93 #endif
94 // CHECK: int has_clang_falthrough_2;
96 #if __has_cpp_attribute(C::fallthrough)
97 int has_clang_falthrough_3;
98 #endif
99 // CHECK: int has_clang_falthrough_3;
101 #if __has_cpp_attribute(CF)
102 int has_clang_falthrough_4;
103 #endif
104 // CHECK: int has_clang_falthrough_4;
106 #define FUNCLIKE1(x) clang::x
107 #if __has_cpp_attribute(FUNCLIKE1(fallthrough))
108 int funclike_1;
109 #endif
110 // CHECK: int funclike_1;
112 #define FUNCLIKE2(x) _Clang::x
113 #if __has_cpp_attribute(FUNCLIKE2(fallthrough))
114 int funclike_2;
115 #endif
116 // CHECK: int funclike_2;
119 // Test for Microsoft __declspec attributes
121 #define DECLSPEC(x) x: __has_declspec_attribute(x)
123 // CHECK: uuid: 1
124 // CHECK: __uuid__: 1
125 DECLSPEC(uuid)
126 DECLSPEC(__uuid__)
128 // CHECK: fallthrough: 0
129 DECLSPEC(fallthrough)
131 namespace PR48462 {
132 // Test that macro expansion of the builtin argument works.
133 #define U uuid
135 #if __has_declspec_attribute(U)
136 int has_uuid;
137 #endif
138 // CHECK: int has_uuid;