Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Lexer / cxx-features.cpp
blob6120b299039e5e4103e58c49cf0f47043f31496d
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++20 -fcxx-exceptions -fsized-deallocation -verify %s
6 // RUN: %clang_cc1 -std=c++23 -fcxx-exceptions -fsized-deallocation -verify %s
7 // RUN: %clang_cc1 -std=c++2c -fcxx-exceptions -fsized-deallocation -verify %s
9 //
10 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s
11 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -DCONCEPTS_TS=1 -verify %s
12 // RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation
13 // RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s
14 // RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify -fsized-deallocation %s
16 // expected-no-diagnostics
18 // FIXME using `defined` in a macro has undefined behavior.
19 #if __cplusplus < 201103L
20 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98)
21 #elif __cplusplus < 201402L
22 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11)
23 #elif __cplusplus < 201703L
24 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14)
25 #elif __cplusplus < 202002L
26 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17)
27 #elif __cplusplus < 202302L
28 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx20 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx20)
29 #elif __cplusplus == 202302L
30 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx23 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx23)
31 #else
32 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx26 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx26)
33 #endif
35 // --- C++26 features ---
37 #if check(placeholder_variables, 202306, 202306, 202306, 202306, 202306, 202306, 202306)
38 #error "wrong value for __cpp_placeholder_variables"
39 #endif
41 // --- C++23 features ---
43 #if check(implicit_move, 0, 0, 0, 0, 0, 202011, 202011)
44 #error "wrong value for __cpp_implicit_move"
45 #endif
47 #if check(size_t_suffix, 0, 0, 0, 0, 0, 202011, 202011)
48 #error "wrong value for __cpp_size_t_suffix"
49 #endif
51 #if check(if_consteval, 0, 0, 0, 0, 0, 202106, 202106)
52 #error "wrong value for __cpp_if_consteval"
53 #endif
55 #if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211, 202211)
56 #error "wrong value for __cpp_multidimensional_subscript"
57 #endif
59 #if check(static_call_operator, 0, 202207, 202207, 202207, 202207, 202207, 202207)
60 #error "wrong value for __cpp_static_call_operator"
61 #endif
63 #if check(named_character_escapes, 202207, 202207, 202207, 202207, 202207, 202207, 202207)
64 #error "wrong value for __cpp_named_character_escapes"
65 #endif
67 #if check(explicit_this_parameter, 0, 0, 0, 0, 0, 0, 0)
68 #error "wrong value for __cpp_explicit_this_parameter"
69 #endif
71 // --- C++20 features ---
73 #if check(aggregate_paren_init, 0, 0, 0, 0, 201902, 201902, 201902)
74 #error "wrong value for __cpp_aggregate_paren_init"
75 #endif
77 #if defined(CHAR8_T) ? check(char8_t, 202207, 202207, 202207, 202207, 202207, 202207, 202207) : \
78 defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0, 0, 0) : \
79 check(char8_t, 0, 0, 0, 0, 202207, 202207, 202207)
80 #error "wrong value for __cpp_char8_t"
81 #endif
83 #if check(concepts, 0, 0, 0, 0, 201907, 201907, 201907)
84 #error "wrong value for __cpp_concepts"
85 #endif
87 #if check(conditional_explicit, 0, 0, 0, 0, 201806, 201806, 201806)
88 #error "wrong value for __cpp_conditional_explicit"
89 #endif
91 #if check(consteval, 0, 0, 0, 0, 202211, 202211, 202211)
92 #error "wrong value for __cpp_consteval"
93 #endif
95 // constexpr checked below
97 #if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907, 201907, 201907)
98 #error "wrong value for __cpp_constexpr_dynamic_alloc"
99 #endif
101 #if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711, 201711, 201711)
102 #error "wrong value for __cpp_constexpr_in_decltype"
103 #endif
105 #if check(constinit, 0, 0, 0, 0, 201907, 201907, 201907)
106 #error "wrong value for __cpp_constinit"
107 #endif
109 // deduction_guides checked below
111 #if check(designated_initializers, 0, 0, 0, 0, 201707, 201707, 201707)
112 #error "wrong value for __cpp_designated_initializers"
113 #endif
115 // generic_lambdas checked below
117 #if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806, 201806, 201806)
118 #error "wrong value for __cpp_impl_destroying_delete"
119 #endif
121 #if check(impl_three_way_comparison, 0, 0, 0, 0, 201907, 201907, 201907)
122 #error "wrong value for __cpp_impl_three_way_comparison"
123 #endif
125 #if check(impl_coroutine, 0, 0, 0, 0, 201902L, 201902L, 201902L)
126 #error "wrong value for __cpp_impl_coroutine"
127 #endif
129 // init_captures checked below
131 #if check(modules, 0, 0, 0, 0, 0, 0, 0)
132 // FIXME: 201907 in C++20
133 #error "wrong value for __cpp_modules"
134 #endif
136 #if check(using_enum, 0, 0, 0, 0, 201907, 201907, 201907)
137 #error "wrong value for __cpp_using_enum"
138 #endif
140 // --- C++17 features ---
142 #if check(hex_float, 0, 0, 0, 201603, 201603, 201603, 201603)
143 #error "wrong value for __cpp_hex_float"
144 #endif
146 #if check(inline_variables, 0, 0, 0, 201606, 201606, 201606, 201606)
147 #error "wrong value for __cpp_inline_variables"
148 #endif
150 #if check(aligned_new, 0, 0, 0, 201606, 201606, 201606, 201606)
151 #error "wrong value for __cpp_aligned_new"
152 #endif
154 #if check(guaranteed_copy_elision, 0, 0, 0, 201606, 201606, 201606, 201606)
155 #error "wrong value for __cpp_guaranteed_copy_elision"
156 #endif
158 #if check(noexcept_function_type, 0, 0, 0, 201510, 201510, 201510, 201510)
159 #error "wrong value for __cpp_noexcept_function_type"
160 #endif
162 #if check(fold_expressions, 0, 0, 0, 201603, 201603, 201603, 201603)
163 #error "wrong value for __cpp_fold_expressions"
164 #endif
166 #if check(capture_star_this, 0, 0, 0, 201603, 201603, 201603, 201603)
167 #error "wrong value for __cpp_capture_star_this"
168 #endif
170 // constexpr checked below
172 #if check(if_constexpr, 0, 0, 0, 201606, 201606, 201606, 201606)
173 #error "wrong value for __cpp_if_constexpr"
174 #endif
176 #if check(deduction_guides, 0, 0, 0, 201703, 201703, 201703, 201703)
177 // FIXME: 201907 in C++20
178 #error "wrong value for __cpp_deduction_guides"
179 #endif
181 #if check(nontype_template_parameter_auto, 0, 0, 0, 201606, 201606, 201606, 201606)
182 #error "wrong value for __cpp_nontype_template_parameter_auto"
183 #endif
185 // This is the old name (from P0096R4) for
186 // __cpp_nontype_template_parameter_auto
187 #if check(template_auto, 0, 0, 0, 201606, 201606, 201606, 201606)
188 #error "wrong value for __cpp_template_auto"
189 #endif
191 #if check(namespace_attributes, 0, 0, 0, 201411, 201411, 201411, 201411)
192 // FIXME: allowed without warning in C++14 and C++11
193 #error "wrong value for __cpp_namespace_attributes"
194 #endif
196 #if check(enumerator_attributes, 0, 0, 0, 201411, 201411, 201411, 201411)
197 // FIXME: allowed without warning in C++14 and C++11
198 #error "wrong value for __cpp_enumerator_attributes"
199 #endif
201 // This is an old name (from P0096R4), now removed from SD-6.
202 #if check(nested_namespace_definitions, 0, 0, 0, 201411, 201411, 201411, 201411)
203 #error "wrong value for __cpp_nested_namespace_definitions"
204 #endif
206 // inheriting_constructors checked below
208 #if check(variadic_using, 0, 0, 0, 201611, 201611, 201611, 201611)
209 #error "wrong value for __cpp_variadic_using"
210 #endif
212 #if check(aggregate_bases, 0, 0, 0, 201603, 201603, 201603, 201603)
213 #error "wrong value for __cpp_aggregate_bases"
214 #endif
216 #if check(structured_bindings, 0, 0, 0, 201606, 201606, 201606, 201606)
217 #error "wrong value for __cpp_structured_bindings"
218 #endif
220 #if check(nontype_template_args, 0, 0, 0, 201411, 201411, 201411, 201411)
221 // FIXME: 201911 in C++20
222 #error "wrong value for __cpp_nontype_template_args"
223 #endif
225 #if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \
226 ? check(template_template_args, 0, 0, 0, 201611, 201611, 201611, 201611) \
227 : check(template_template_args, 0, 0, 0, 0, 0, 0, 0)
228 #error "wrong value for __cpp_template_template_args"
229 #endif
231 // --- C++14 features ---
233 #if check(binary_literals, 0, 0, 201304, 201304, 201304, 201304, 201304)
234 #error "wrong value for __cpp_binary_literals"
235 #endif
237 // (Removed from SD-6.)
238 #if check(digit_separators, 0, 0, 201309, 201309, 201309, 201309, 201309)
239 #error "wrong value for __cpp_digit_separators"
240 #endif
242 #if check(init_captures, 0, 0, 201304, 201304, 201803, 201803, 201803)
243 #error "wrong value for __cpp_init_captures"
244 #endif
246 #if check(generic_lambdas, 0, 0, 201304, 201304, 201707, 201707, 201707)
247 #error "wrong value for __cpp_generic_lambdas"
248 #endif
250 #if check(sized_deallocation, 0, 0, 201309, 201309, 201309, 201309, 201309)
251 #error "wrong value for __cpp_sized_deallocation"
252 #endif
254 // constexpr checked below
256 #if check(decltype_auto, 0, 0, 201304, 201304, 201304, 201304, 201304)
257 #error "wrong value for __cpp_decltype_auto"
258 #endif
260 #if check(return_type_deduction, 0, 0, 201304, 201304, 201304, 201304, 201304)
261 #error "wrong value for __cpp_return_type_deduction"
262 #endif
264 #if check(runtime_arrays, 0, 0, 0, 0, 0, 0, 0)
265 #error "wrong value for __cpp_runtime_arrays"
266 #endif
268 #if check(aggregate_nsdmi, 0, 0, 201304, 201304, 201304, 201304, 201304)
269 #error "wrong value for __cpp_aggregate_nsdmi"
270 #endif
272 #if check(variable_templates, 0, 0, 201304, 201304, 201304, 201304, 201304)
273 #error "wrong value for __cpp_variable_templates"
274 #endif
276 // --- C++11 features ---
278 #if check(unicode_characters, 0, 200704, 200704, 200704, 200704, 200704, 200704)
279 #error "wrong value for __cpp_unicode_characters"
280 #endif
282 #if check(raw_strings, 0, 200710, 200710, 200710, 200710, 200710, 200710)
283 #error "wrong value for __cpp_raw_strings"
284 #endif
286 #if check(unicode_literals, 0, 200710, 200710, 200710, 200710, 200710, 200710)
287 #error "wrong value for __cpp_unicode_literals"
288 #endif
290 #if check(user_defined_literals, 0, 200809, 200809, 200809, 200809, 200809, 200809)
291 #error "wrong value for __cpp_user_defined_literals"
292 #endif
294 #if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0, 0, 0, 0) : \
295 check(threadsafe_static_init, 200806, 200806, 200806, 200806, 200806, 200806, 200806)
296 #error "wrong value for __cpp_threadsafe_static_init"
297 #endif
299 #if check(lambdas, 0, 200907, 200907, 200907, 200907, 200907, 200907)
300 #error "wrong value for __cpp_lambdas"
301 #endif
303 #if check(constexpr, 0, 200704, 201304, 201603, 201907, 202211, 202306)
304 #error "wrong value for __cpp_constexpr"
305 #endif
307 #if check(range_based_for, 0, 200907, 200907, 201603, 201603, 201603, 201603)
308 #error "wrong value for __cpp_range_based_for"
309 #endif
311 #if check(static_assert, 0, 200410, 200410, 201411, 201411, 201411, 202306)
312 #error "wrong value for __cpp_static_assert"
313 #endif
315 #if check(decltype, 0, 200707, 200707, 200707, 200707, 200707, 200707)
316 #error "wrong value for __cpp_decltype"
317 #endif
319 #if check(attributes, 0, 200809, 200809, 200809, 200809, 200809, 200809)
320 #error "wrong value for __cpp_attributes"
321 #endif
323 #if check(rvalue_references, 0, 200610, 200610, 200610, 200610, 200610, 200610)
324 #error "wrong value for __cpp_rvalue_references"
325 #endif
327 #if check(variadic_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704)
328 #error "wrong value for __cpp_variadic_templates"
329 #endif
331 #if check(initializer_lists, 0, 200806, 200806, 200806, 200806, 200806, 200806)
332 #error "wrong value for __cpp_initializer_lists"
333 #endif
335 #if check(delegating_constructors, 0, 200604, 200604, 200604, 200604, 200604, 200604)
336 #error "wrong value for __cpp_delegating_constructors"
337 #endif
339 #if check(nsdmi, 0, 200809, 200809, 200809, 200809, 200809, 200809)
340 #error "wrong value for __cpp_nsdmi"
341 #endif
343 #if check(inheriting_constructors, 0, 201511, 201511, 201511, 201511, 201511, 201511)
344 #error "wrong value for __cpp_inheriting_constructors"
345 #endif
347 #if check(ref_qualifiers, 0, 200710, 200710, 200710, 200710, 200710, 200710)
348 #error "wrong value for __cpp_ref_qualifiers"
349 #endif
351 #if check(alias_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704)
352 #error "wrong value for __cpp_alias_templates"
353 #endif
355 // --- C++98 features ---
357 #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0, 0, 0, 0 ) \
358 : check(rtti, 199711, 199711, 199711, 199711, 199711, 199711, 199711)
359 #error "wrong value for __cpp_rtti"
360 #endif
362 #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0, 0, 0, 0) \
363 : check(exceptions, 199711, 199711, 199711, 199711, 199711, 199711, 199711)
364 #error "wrong value for __cpp_exceptions"
365 #endif