]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Lexer/cxx-features.cpp
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / test / Lexer / cxx-features.cpp
1 // RUN: %clang_cc1 -std=c++98 -fcxx-exceptions -verify %s
2 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -verify %s
3 // RUN: %clang_cc1 -std=c++14 -fcxx-exceptions -fsized-deallocation -verify %s
4 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -verify %s
5 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fsized-deallocation -verify %s
6 //
7 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s
8 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -fconcepts-ts -DCONCEPTS_TS=1 -verify %s
9 // RUN: %clang_cc1 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation
10 // RUN: %clang_cc1 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s
11 // RUN: %clang_cc1 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s
12
13 // expected-no-diagnostics
14
15 // FIXME using `defined` in a macro has undefined behavior.
16 #if __cplusplus < 201103L
17 #define check(macro, cxx98, cxx11, cxx14, cxx17) cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98
18 #elif __cplusplus < 201402L
19 #define check(macro, cxx98, cxx11, cxx14, cxx17) cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11
20 #elif __cplusplus < 201406L
21 #define check(macro, cxx98, cxx11, cxx14, cxx17) cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14
22 #else
23 #define check(macro, cxx98, cxx11, cxx14, cxx17) cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17
24 #endif
25
26 // --- C++17 features ---
27
28 #if check(hex_float, 0, 0, 0, 201603)
29 #error "wrong value for __cpp_hex_float"
30 #endif
31
32 #if check(inline_variables, 0, 0, 0, 201606)
33 #error "wrong value for __cpp_inline_variables"
34 #endif
35
36 #if check(aligned_new, 0, 0, 0, 201606)
37 #error "wrong value for __cpp_aligned_new"
38 #endif
39
40 #if check(guaranteed_copy_elision, 0, 0, 0, 201606)
41 #error "wrong value for __cpp_guaranteed_copy_elision"
42 #endif
43
44 #if check(noexcept_function_type, 0, 0, 0, 201510)
45 #error "wrong value for __cpp_noexcept_function_type"
46 #endif
47
48 #if check(fold_expressions, 0, 0, 0, 201603)
49 #error "wrong value for __cpp_fold_expressions"
50 #endif
51
52 #if check(capture_star_this, 0, 0, 0, 201603)
53 #error "wrong value for __cpp_capture_star_this"
54 #endif
55
56 // constexpr checked below
57
58 #if check(if_constexpr, 0, 0, 0, 201606)
59 #error "wrong value for __cpp_if_constexpr"
60 #endif
61
62 // range_based_for checked below
63
64 // static_assert checked below
65
66 #if check(deduction_guides, 0, 0, 0, 201703)
67 #error "wrong value for __cpp_deduction_guides"
68 #endif
69
70 #if check(nontype_template_parameter_auto, 0, 0, 0, 201606)
71 #error "wrong value for __cpp_nontype_template_parameter_auto"
72 #endif
73
74 // This is the old name (from P0096R4) for
75 // __cpp_nontype_template_parameter_auto
76 #if check(template_auto, 0, 0, 0, 201606)
77 #error "wrong value for __cpp_template_auto"
78 #endif
79
80 #if check(namespace_attributes, 0, 0, 0, 201411)
81 // FIXME: allowed without warning in C++14 and C++11
82 #error "wrong value for __cpp_namespace_attributes"
83 #endif
84
85 #if check(enumerator_attributes, 0, 0, 0, 201411)
86 // FIXME: allowed without warning in C++14 and C++11
87 #error "wrong value for __cpp_enumerator_attributes"
88 #endif
89
90 // This is an old name (from P0096R4), now removed from SD-6.
91 #if check(nested_namespace_definitions, 0, 0, 0, 201411)
92 #error "wrong value for __cpp_nested_namespace_definitions"
93 #endif
94
95 // inheriting_constructors checked below
96
97 #if check(variadic_using, 0, 0, 0, 201611)
98 #error "wrong value for __cpp_variadic_using"
99 #endif
100
101 #if check(aggregate_bases, 0, 0, 0, 201603)
102 #error "wrong value for __cpp_aggregate_bases"
103 #endif
104
105 #if check(structured_bindings, 0, 0, 0, 201606)
106 #error "wrong value for __cpp_structured_bindings"
107 #endif
108
109 #if check(nontype_template_args, 0, 0, 0, 201411)
110 #error "wrong value for __cpp_nontype_template_args"
111 #endif
112
113 #if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \
114     ? check(template_template_args, 0, 0, 0, 201611) \
115     : check(template_template_args, 0, 0, 0, 0)
116 #error "wrong value for __cpp_template_template_args"
117 #endif
118
119 // --- C++14 features ---
120
121 #if check(binary_literals, 0, 0, 201304, 201304)
122 #error "wrong value for __cpp_binary_literals"
123 #endif
124
125 // (Removed from SD-6.)
126 #if check(digit_separators, 0, 0, 201309, 201309)
127 #error "wrong value for __cpp_digit_separators"
128 #endif
129
130 #if check(init_captures, 0, 0, 201304, 201304)
131 #error "wrong value for __cpp_init_captures"
132 #endif
133
134 #if check(generic_lambdas, 0, 0, 201304, 201304)
135 #error "wrong value for __cpp_generic_lambdas"
136 #endif
137
138 #if check(sized_deallocation, 0, 0, 201309, 201309)
139 #error "wrong value for __cpp_sized_deallocation"
140 #endif
141
142 // constexpr checked below
143
144 #if check(decltype_auto, 0, 0, 201304, 201304)
145 #error "wrong value for __cpp_decltype_auto"
146 #endif
147
148 #if check(return_type_deduction, 0, 0, 201304, 201304)
149 #error "wrong value for __cpp_return_type_deduction"
150 #endif
151
152 #if check(runtime_arrays, 0, 0, 0, 0)
153 #error "wrong value for __cpp_runtime_arrays"
154 #endif
155
156 #if check(aggregate_nsdmi, 0, 0, 201304, 201304)
157 #error "wrong value for __cpp_aggregate_nsdmi"
158 #endif
159
160 #if check(variable_templates, 0, 0, 201304, 201304)
161 #error "wrong value for __cpp_variable_templates"
162 #endif
163
164 // --- C++11 features ---
165
166 #if check(unicode_characters, 0, 200704, 200704, 200704)
167 #error "wrong value for __cpp_unicode_characters"
168 #endif
169
170 #if check(raw_strings, 0, 200710, 200710, 200710)
171 #error "wrong value for __cpp_raw_strings"
172 #endif
173
174 #if check(unicode_literals, 0, 200710, 200710, 200710)
175 #error "wrong value for __cpp_unicode_literals"
176 #endif
177
178 #if check(user_defined_literals, 0, 200809, 200809, 200809)
179 #error "wrong value for __cpp_user_defined_literals"
180 #endif
181
182 #if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0) : check(threadsafe_static_init, 200806, 200806, 200806, 200806)
183 #error "wrong value for __cpp_threadsafe_static_init"
184 #endif
185
186 #if check(lambdas, 0, 200907, 200907, 200907)
187 #error "wrong value for __cpp_lambdas"
188 #endif
189
190 #if check(constexpr, 0, 200704, 201304, 201603)
191 #error "wrong value for __cpp_constexpr"
192 #endif
193
194 #if check(range_based_for, 0, 200907, 200907, 201603)
195 #error "wrong value for __cpp_range_based_for"
196 #endif
197
198 #if check(static_assert, 0, 200410, 200410, 201411)
199 #error "wrong value for __cpp_static_assert"
200 #endif
201
202 #if check(decltype, 0, 200707, 200707, 200707)
203 #error "wrong value for __cpp_decltype"
204 #endif
205
206 #if check(attributes, 0, 200809, 200809, 200809)
207 #error "wrong value for __cpp_attributes"
208 #endif
209
210 #if check(rvalue_references, 0, 200610, 200610, 200610)
211 #error "wrong value for __cpp_rvalue_references"
212 #endif
213
214 #if check(variadic_templates, 0, 200704, 200704, 200704)
215 #error "wrong value for __cpp_variadic_templates"
216 #endif
217
218 #if check(initializer_lists, 0, 200806, 200806, 200806)
219 #error "wrong value for __cpp_initializer_lists"
220 #endif
221
222 #if check(delegating_constructors, 0, 200604, 200604, 200604)
223 #error "wrong value for __cpp_delegating_constructors"
224 #endif
225
226 #if check(nsdmi, 0, 200809, 200809, 200809)
227 #error "wrong value for __cpp_nsdmi"
228 #endif
229
230 #if check(inheriting_constructors, 0, 201511, 201511, 201511)
231 #error "wrong value for __cpp_inheriting_constructors"
232 #endif
233
234 #if check(ref_qualifiers, 0, 200710, 200710, 200710)
235 #error "wrong value for __cpp_ref_qualifiers"
236 #endif
237
238 #if check(alias_templates, 0, 200704, 200704, 200704)
239 #error "wrong value for __cpp_alias_templates"
240 #endif
241
242 // --- C++98 features ---
243
244 #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711)
245 #error "wrong value for __cpp_rtti"
246 #endif
247
248 #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711)
249 #error "wrong value for __cpp_exceptions"
250 #endif
251
252 // --- TS features --
253
254 #if check(experimental_concepts, 0, 0, CONCEPTS_TS, CONCEPTS_TS)
255 #error "wrong value for __cpp_experimental_concepts"
256 #endif
257
258 #if defined(COROUTINES) ? check(coroutines, 201703L, 201703L, 201703L, 201703L) : check(coroutines, 0, 0, 0, 0)
259 #error "wrong value for __cpp_coroutines"
260 #endif
261
262 // --- not-yet-standard features --
263
264 #if defined(CHAR8_T) ? check(char8_t, 201803, 201803, 201803, 201803) : check(char8_t, 0, 0, 0, 0)
265 #error "wrong value for __cpp_char8_t"
266 #endif