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 -verify %s
4 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -verify %s
5 // RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -verify %s
6 // RUN: %clang_cc1 -std=c++23 -fcxx-exceptions -verify %s
7 // RUN: %clang_cc1 -std=c++2c -fcxx-exceptions -verify %s
10 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fno-relaxed-template-template-args -DNO_RELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s
11 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -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
13 // RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify %s
14 // RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify %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)
32 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx26 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx26)
35 // --- C++26 features ---
37 #if check(variadic_friend, 202403, 202403, 202403, 202403, 202403, 202403, 202403)
38 #error "wrong value for __cpp_variadic_friend"
41 #if check(deleted_function, 202403, 202403, 202403, 202403, 202403, 202403, 202403)
42 #error "wrong value for __cpp_deleted_function"
45 #if check(pack_indexing, 202311, 202311, 202311, 202311, 202311, 202311, 202311)
46 #error "wrong value for __cpp_pack_indexing"
49 #if check(placeholder_variables, 202306, 202306, 202306, 202306, 202306, 202306, 202306)
50 #error "wrong value for __cpp_placeholder_variables"
53 // --- C++23 features ---
55 #if check(auto_cast, 0, 0, 0, 0, 0, 202110, 202110)
56 #error "wrong value for __cpp_auto_cast"
60 #if check(implicit_move, 0, 0, 0, 0, 0, 202207, 202207)
61 #error "wrong value for __cpp_implicit_move"
64 #if check(size_t_suffix, 0, 0, 0, 0, 0, 202011, 202011)
65 #error "wrong value for __cpp_size_t_suffix"
68 #if check(if_consteval, 0, 0, 0, 0, 0, 202106, 202106)
69 #error "wrong value for __cpp_if_consteval"
72 #if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211, 202211)
73 #error "wrong value for __cpp_multidimensional_subscript"
76 #if check(static_call_operator, 0, 202207, 202207, 202207, 202207, 202207, 202207)
77 #error "wrong value for __cpp_static_call_operator"
80 #if check(named_character_escapes, 202207, 202207, 202207, 202207, 202207, 202207, 202207)
81 #error "wrong value for __cpp_named_character_escapes"
84 #if check(explicit_this_parameter, 0, 0, 0, 0, 0, 0, 0)
85 #error "wrong value for __cpp_explicit_this_parameter"
88 // --- C++20 features ---
90 #if check(aggregate_paren_init, 0, 0, 0, 0, 201902, 201902, 201902)
91 #error "wrong value for __cpp_aggregate_paren_init"
94 #if defined(CHAR8_T) ? check(char8_t, 202207, 202207, 202207, 202207, 202207, 202207, 202207) : \
95 defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0, 0, 0) : \
96 check(char8_t, 0, 0, 0, 0, 202207, 202207, 202207)
97 #error "wrong value for __cpp_char8_t"
100 #if check(concepts, 0, 0, 0, 0, 202002, 202002, 202002)
101 #error "wrong value for __cpp_concepts"
104 #if check(conditional_explicit, 0, 0, 0, 0, 201806, 201806, 201806)
105 #error "wrong value for __cpp_conditional_explicit"
108 #if check(consteval, 0, 0, 0, 0, 202211, 202211, 202211)
109 #error "wrong value for __cpp_consteval"
112 // constexpr checked below
114 #if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907, 201907, 201907)
115 #error "wrong value for __cpp_constexpr_dynamic_alloc"
118 #if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711, 201711, 201711)
119 #error "wrong value for __cpp_constexpr_in_decltype"
122 #if check(constinit, 0, 0, 0, 0, 201907, 201907, 201907)
123 #error "wrong value for __cpp_constinit"
126 // deduction_guides checked below
128 #if check(designated_initializers, 0, 0, 0, 0, 201707, 201707, 201707)
129 #error "wrong value for __cpp_designated_initializers"
132 // generic_lambdas checked below
134 #if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806, 201806, 201806)
135 #error "wrong value for __cpp_impl_destroying_delete"
138 #if check(impl_three_way_comparison, 0, 0, 0, 0, 201907, 201907, 201907)
139 #error "wrong value for __cpp_impl_three_way_comparison"
142 #if check(impl_coroutine, 0, 0, 0, 0, 201902L, 201902L, 201902L)
143 #error "wrong value for __cpp_impl_coroutine"
146 // init_captures checked below
148 #if check(modules, 0, 0, 0, 0, 0, 0, 0)
149 // FIXME: 201907 in C++20
150 #error "wrong value for __cpp_modules"
153 #if check(using_enum, 0, 0, 0, 0, 201907, 201907, 201907)
154 #error "wrong value for __cpp_using_enum"
157 // --- C++17 features ---
159 #if check(hex_float, 0, 0, 0, 201603, 201603, 201603, 201603)
160 #error "wrong value for __cpp_hex_float"
163 #if check(inline_variables, 0, 0, 0, 201606, 201606, 201606, 201606)
164 #error "wrong value for __cpp_inline_variables"
167 #if check(aligned_new, 0, 0, 0, 201606, 201606, 201606, 201606)
168 #error "wrong value for __cpp_aligned_new"
171 #if check(guaranteed_copy_elision, 0, 0, 0, 201606, 201606, 201606, 201606)
172 #error "wrong value for __cpp_guaranteed_copy_elision"
175 #if check(noexcept_function_type, 0, 0, 0, 201510, 201510, 201510, 201510)
176 #error "wrong value for __cpp_noexcept_function_type"
179 #if check(fold_expressions, 0, 0, 0, 201603, 201603, 201603, 201603)
180 #error "wrong value for __cpp_fold_expressions"
183 #if check(capture_star_this, 0, 0, 0, 201603, 201603, 201603, 201603)
184 #error "wrong value for __cpp_capture_star_this"
187 // constexpr checked below
189 #if check(if_constexpr, 0, 0, 0, 201606, 201606, 201606, 201606)
190 #error "wrong value for __cpp_if_constexpr"
193 #if check(deduction_guides, 0, 0, 0, 201703, 201703, 201703, 201703)
194 // FIXME: 201907 in C++20
195 #error "wrong value for __cpp_deduction_guides"
198 #if check(nontype_template_parameter_auto, 0, 0, 0, 201606, 201606, 201606, 201606)
199 #error "wrong value for __cpp_nontype_template_parameter_auto"
202 // This is the old name (from P0096R4) for
203 // __cpp_nontype_template_parameter_auto
204 #if check(template_auto, 0, 0, 0, 201606, 201606, 201606, 201606)
205 #error "wrong value for __cpp_template_auto"
208 #if check(namespace_attributes, 0, 0, 0, 201411, 201411, 201411, 201411)
209 // FIXME: allowed without warning in C++14 and C++11
210 #error "wrong value for __cpp_namespace_attributes"
213 #if check(enumerator_attributes, 0, 0, 0, 201411, 201411, 201411, 201411)
214 // FIXME: allowed without warning in C++14 and C++11
215 #error "wrong value for __cpp_enumerator_attributes"
218 // This is an old name (from P0096R4), now removed from SD-6.
219 #if check(nested_namespace_definitions, 0, 0, 0, 201411, 201411, 201411, 201411)
220 #error "wrong value for __cpp_nested_namespace_definitions"
223 // inheriting_constructors checked below
225 #if check(variadic_using, 0, 0, 0, 201611, 201611, 201611, 201611)
226 #error "wrong value for __cpp_variadic_using"
229 #if check(aggregate_bases, 0, 0, 0, 201603, 201603, 201603, 201603)
230 #error "wrong value for __cpp_aggregate_bases"
233 #if check(structured_bindings, 0, 0, 0, 202403L, 202403L, 202403L, 202403L)
234 #error "wrong value for __cpp_structured_bindings"
237 #if check(nontype_template_args, 0, 0, 0, 201411, 201411, 201411, 201411)
238 // FIXME: 201911 in C++20
239 #error "wrong value for __cpp_nontype_template_args"
242 #if !defined(NO_RELAXED_TEMPLATE_TEMPLATE_ARGS) \
243 ? check(template_template_args, 201611, 201611, 201611, 201611, 201611, 201611, 201611) \
244 : check(template_template_args, 0, 0, 0, 0, 0, 0, 0)
245 #error "wrong value for __cpp_template_template_args"
248 // --- C++14 features ---
250 #if check(binary_literals, 0, 0, 201304, 201304, 201304, 201304, 201304)
251 #error "wrong value for __cpp_binary_literals"
254 // (Removed from SD-6.)
255 #if check(digit_separators, 0, 0, 201309, 201309, 201309, 201309, 201309)
256 #error "wrong value for __cpp_digit_separators"
259 #if check(init_captures, 0, 0, 201304, 201304, 201803, 201803, 201803)
260 #error "wrong value for __cpp_init_captures"
263 #if check(generic_lambdas, 0, 0, 201304, 201304, 201707, 201707, 201707)
264 #error "wrong value for __cpp_generic_lambdas"
267 #if check(sized_deallocation, 0, 0, 201309, 201309, 201309, 201309, 201309)
268 #error "wrong value for __cpp_sized_deallocation"
271 // constexpr checked below
273 #if check(decltype_auto, 0, 0, 201304, 201304, 201304, 201304, 201304)
274 #error "wrong value for __cpp_decltype_auto"
277 #if check(return_type_deduction, 0, 0, 201304, 201304, 201304, 201304, 201304)
278 #error "wrong value for __cpp_return_type_deduction"
281 #if check(runtime_arrays, 0, 0, 0, 0, 0, 0, 0)
282 #error "wrong value for __cpp_runtime_arrays"
285 #if check(aggregate_nsdmi, 0, 0, 201304, 201304, 201304, 201304, 201304)
286 #error "wrong value for __cpp_aggregate_nsdmi"
289 #if check(variable_templates, 0, 0, 201304, 201304, 201304, 201304, 201304)
290 #error "wrong value for __cpp_variable_templates"
293 // --- C++11 features ---
295 #if check(unicode_characters, 0, 200704, 200704, 200704, 200704, 200704, 200704)
296 #error "wrong value for __cpp_unicode_characters"
299 #if check(raw_strings, 0, 200710, 200710, 200710, 200710, 200710, 200710)
300 #error "wrong value for __cpp_raw_strings"
303 #if check(unicode_literals, 0, 200710, 200710, 200710, 200710, 200710, 200710)
304 #error "wrong value for __cpp_unicode_literals"
307 #if check(user_defined_literals, 0, 200809, 200809, 200809, 200809, 200809, 200809)
308 #error "wrong value for __cpp_user_defined_literals"
311 #if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0, 0, 0, 0) : \
312 check(threadsafe_static_init, 200806, 200806, 200806, 200806, 200806, 200806, 200806)
313 #error "wrong value for __cpp_threadsafe_static_init"
316 #if check(lambdas, 0, 200907, 200907, 200907, 200907, 200907, 200907)
317 #error "wrong value for __cpp_lambdas"
320 #if check(constexpr, 0, 200704, 201304, 201603, 201907, 202211, 202406L)
321 #error "wrong value for __cpp_constexpr"
324 #if check(range_based_for, 0, 200907, 200907, 201603, 201603, 202211, 202211)
325 #error "wrong value for __cpp_range_based_for"
328 #if check(static_assert, 0, 202306, 202306, 202306, 202306, 202306, 202306)
329 #error "wrong value for __cpp_static_assert"
332 #if check(decltype, 0, 200707, 200707, 200707, 200707, 200707, 200707)
333 #error "wrong value for __cpp_decltype"
336 #if check(attributes, 0, 200809, 200809, 200809, 200809, 200809, 200809)
337 #error "wrong value for __cpp_attributes"
340 #if check(rvalue_references, 0, 200610, 200610, 200610, 200610, 200610, 200610)
341 #error "wrong value for __cpp_rvalue_references"
344 #if check(variadic_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704)
345 #error "wrong value for __cpp_variadic_templates"
348 #if check(initializer_lists, 0, 200806, 200806, 200806, 200806, 200806, 200806)
349 #error "wrong value for __cpp_initializer_lists"
352 #if check(delegating_constructors, 0, 200604, 200604, 200604, 200604, 200604, 200604)
353 #error "wrong value for __cpp_delegating_constructors"
356 #if check(nsdmi, 0, 200809, 200809, 200809, 200809, 200809, 200809)
357 #error "wrong value for __cpp_nsdmi"
360 #if check(inheriting_constructors, 0, 201511, 201511, 201511, 201511, 201511, 201511)
361 #error "wrong value for __cpp_inheriting_constructors"
364 #if check(ref_qualifiers, 0, 200710, 200710, 200710, 200710, 200710, 200710)
365 #error "wrong value for __cpp_ref_qualifiers"
368 #if check(alias_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704)
369 #error "wrong value for __cpp_alias_templates"
372 // --- C++98 features ---
374 #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0, 0, 0, 0 ) \
375 : check(rtti, 199711, 199711, 199711, 199711, 199711, 199711, 199711)
376 #error "wrong value for __cpp_rtti"
379 #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0, 0, 0, 0) \
380 : check(exceptions, 199711, 199711, 199711, 199711, 199711, 199711, 199711)
381 #error "wrong value for __cpp_exceptions"