384 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -fcxx-exceptions -verify %s2// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -verify %s3// RUN: %clang_cc1 -std=c++14 -fcxx-exceptions -verify %s4// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -verify %s5// RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -verify %s6// RUN: %clang_cc1 -std=c++23 -fcxx-exceptions -verify %s7// RUN: %clang_cc1 -std=c++2c -fcxx-exceptions -verify %s8 9//10// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -DCONCEPTS_TS=1 -verify %s11// RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS12// RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify %s13// RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify %s14 15// expected-no-diagnostics16 17// FIXME using `defined` in a macro has undefined behavior.18#if __cplusplus < 201103L19#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98)20#elif __cplusplus < 201402L21#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11)22#elif __cplusplus < 201703L23#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14)24#elif __cplusplus < 202002L25#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17)26#elif __cplusplus < 202302L27#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx20 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx20)28#elif __cplusplus == 202302L29#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx23 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx23)30#else31#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx26 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx26)32#endif33 34// --- C++26 features ---35 36#if check(variadic_friend, 202403, 202403, 202403, 202403, 202403, 202403, 202403)37#error "wrong value for __cpp_variadic_friend"38#endif39 40#if check(deleted_function, 202403, 202403, 202403, 202403, 202403, 202403, 202403)41#error "wrong value for __cpp_deleted_function"42#endif43 44#if check(pack_indexing, 202311, 202311, 202311, 202311, 202311, 202311, 202311)45#error "wrong value for __cpp_pack_indexing"46#endif47 48#if check(placeholder_variables, 202306, 202306, 202306, 202306, 202306, 202306, 202306)49#error "wrong value for __cpp_placeholder_variables"50#endif51 52#if check(trivial_relocatability, 202502, 202502, 202502, 202502, 202502, 202502, 202502)53#error "wrong value for __cpp_trivial_relocatability"54#endif55 56// --- C++23 features ---57 58#if check(auto_cast, 0, 0, 0, 0, 0, 202110, 202110)59#error "wrong value for __cpp_auto_cast"60#endif61 62 63#if check(implicit_move, 0, 0, 0, 0, 0, 202207, 202207)64#error "wrong value for __cpp_implicit_move"65#endif66 67#if check(size_t_suffix, 0, 0, 0, 0, 0, 202011, 202011)68#error "wrong value for __cpp_size_t_suffix"69#endif70 71#if check(if_consteval, 0, 0, 0, 0, 0, 202106, 202106)72#error "wrong value for __cpp_if_consteval"73#endif74 75#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211, 202211)76#error "wrong value for __cpp_multidimensional_subscript"77#endif78 79#if check(static_call_operator, 0, 202207, 202207, 202207, 202207, 202207, 202207)80#error "wrong value for __cpp_static_call_operator"81#endif82 83#if check(named_character_escapes, 202207, 202207, 202207, 202207, 202207, 202207, 202207)84#error "wrong value for __cpp_named_character_escapes"85#endif86 87#if check(explicit_this_parameter, 0, 0, 0, 0, 0, 202110L, 202110L)88#error "wrong value for __cpp_explicit_this_parameter"89#endif90 91// --- C++20 features ---92 93#if check(aggregate_paren_init, 0, 0, 0, 0, 201902, 201902, 201902)94#error "wrong value for __cpp_aggregate_paren_init"95#endif96 97#if defined(CHAR8_T) ? check(char8_t, 202207, 202207, 202207, 202207, 202207, 202207, 202207) : \98 defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0, 0, 0) : \99 check(char8_t, 0, 0, 0, 0, 202207, 202207, 202207)100#error "wrong value for __cpp_char8_t"101#endif102 103#if check(concepts, 0, 0, 0, 0, 202002, 202002, 202002)104#error "wrong value for __cpp_concepts"105#endif106 107#if check(conditional_explicit, 0, 0, 0, 0, 201806, 201806, 201806)108#error "wrong value for __cpp_conditional_explicit"109#endif110 111#if check(consteval, 0, 0, 0, 0, 202211, 202211, 202211)112#error "wrong value for __cpp_consteval"113#endif114 115// constexpr checked below116 117#if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907, 201907, 201907)118#error "wrong value for __cpp_constexpr_dynamic_alloc"119#endif120 121#if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711, 201711, 201711)122#error "wrong value for __cpp_constexpr_in_decltype"123#endif124 125#if check(constinit, 0, 0, 0, 0, 201907, 201907, 201907)126#error "wrong value for __cpp_constinit"127#endif128 129// deduction_guides checked below130 131#if check(designated_initializers, 0, 0, 0, 0, 201707, 201707, 201707)132#error "wrong value for __cpp_designated_initializers"133#endif134 135// generic_lambdas checked below136 137#if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806, 201806, 201806)138#error "wrong value for __cpp_impl_destroying_delete"139#endif140 141#if check(impl_three_way_comparison, 0, 0, 0, 0, 201907, 201907, 201907)142#error "wrong value for __cpp_impl_three_way_comparison"143#endif144 145#if check(impl_coroutine, 0, 0, 0, 0, 201902L, 201902L, 201902L)146#error "wrong value for __cpp_impl_coroutine"147#endif148 149// init_captures checked below150 151#if check(modules, 0, 0, 0, 0, 1, 1, 1)152// FIXME: 201907 in C++20153#error "wrong value for __cpp_modules"154#endif155 156#if check(using_enum, 0, 0, 0, 0, 201907, 201907, 201907)157#error "wrong value for __cpp_using_enum"158#endif159 160// --- C++17 features ---161 162#if check(hex_float, 0, 0, 0, 201603, 201603, 201603, 201603)163#error "wrong value for __cpp_hex_float"164#endif165 166#if check(inline_variables, 0, 0, 0, 201606, 201606, 201606, 201606)167#error "wrong value for __cpp_inline_variables"168#endif169 170#if check(aligned_new, 0, 0, 0, 201606, 201606, 201606, 201606)171#error "wrong value for __cpp_aligned_new"172#endif173 174#if check(guaranteed_copy_elision, 0, 0, 0, 201606, 201606, 201606, 201606)175#error "wrong value for __cpp_guaranteed_copy_elision"176#endif177 178#if check(noexcept_function_type, 0, 0, 0, 201510, 201510, 201510, 201510)179#error "wrong value for __cpp_noexcept_function_type"180#endif181 182#if check(fold_expressions, 0, 0, 0, 201603, 201603, 201603, 201603)183#error "wrong value for __cpp_fold_expressions"184#endif185 186#if check(capture_star_this, 0, 0, 0, 201603, 201603, 201603, 201603)187#error "wrong value for __cpp_capture_star_this"188#endif189 190// constexpr checked below191 192#if check(if_constexpr, 0, 0, 0, 201606, 201606, 201606, 201606)193#error "wrong value for __cpp_if_constexpr"194#endif195 196#if check(deduction_guides, 0, 0, 0, 201703, 201703, 201703, 201703)197// FIXME: 201907 in C++20198#error "wrong value for __cpp_deduction_guides"199#endif200 201#if check(nontype_template_parameter_auto, 0, 0, 0, 201606, 201606, 201606, 201606)202#error "wrong value for __cpp_nontype_template_parameter_auto"203#endif204 205// This is the old name (from P0096R4) for206// __cpp_nontype_template_parameter_auto207#if check(template_auto, 0, 0, 0, 201606, 201606, 201606, 201606)208#error "wrong value for __cpp_template_auto"209#endif210 211#if check(namespace_attributes, 0, 0, 0, 201411, 201411, 201411, 201411)212// FIXME: allowed without warning in C++14 and C++11213#error "wrong value for __cpp_namespace_attributes"214#endif215 216#if check(enumerator_attributes, 0, 0, 0, 201411, 201411, 201411, 201411)217// FIXME: allowed without warning in C++14 and C++11218#error "wrong value for __cpp_enumerator_attributes"219#endif220 221// This is an old name (from P0096R4), now removed from SD-6.222#if check(nested_namespace_definitions, 0, 0, 0, 201411, 201411, 201411, 201411)223#error "wrong value for __cpp_nested_namespace_definitions"224#endif225 226// inheriting_constructors checked below227 228#if check(variadic_using, 0, 0, 0, 201611, 201611, 201611, 201611)229#error "wrong value for __cpp_variadic_using"230#endif231 232#if check(aggregate_bases, 0, 0, 0, 201603, 201603, 201603, 201603)233#error "wrong value for __cpp_aggregate_bases"234#endif235 236#if check(structured_bindings, 0, 0, 0, 202411L, 202411L, 202411L, 202411L)237#error "wrong value for __cpp_structured_bindings"238#endif239 240#if check(nontype_template_args, 0, 0, 0, 201411, 201411, 201411, 201411)241// FIXME: 201911 in C++20242#error "wrong value for __cpp_nontype_template_args"243#endif244 245#if check(template_template_args, 201611, 201611, 201611, 201611, 201611, 201611, 201611)246#error "wrong value for __cpp_template_template_args"247#endif248 249// --- C++14 features ---250 251#if check(binary_literals, 0, 0, 201304, 201304, 201304, 201304, 201304)252#error "wrong value for __cpp_binary_literals"253#endif254 255// (Removed from SD-6.)256#if check(digit_separators, 0, 0, 201309, 201309, 201309, 201309, 201309)257#error "wrong value for __cpp_digit_separators"258#endif259 260#if check(init_captures, 0, 0, 201304, 201304, 201803, 201803, 201803)261#error "wrong value for __cpp_init_captures"262#endif263 264#if check(generic_lambdas, 0, 0, 201304, 201304, 201707, 201707, 201707)265#error "wrong value for __cpp_generic_lambdas"266#endif267 268#if check(sized_deallocation, 0, 0, 201309, 201309, 201309, 201309, 201309)269#error "wrong value for __cpp_sized_deallocation"270#endif271 272// constexpr checked below273 274#if check(decltype_auto, 0, 0, 201304, 201304, 201304, 201304, 201304)275#error "wrong value for __cpp_decltype_auto"276#endif277 278#if check(return_type_deduction, 0, 0, 201304, 201304, 201304, 201304, 201304)279#error "wrong value for __cpp_return_type_deduction"280#endif281 282#if check(runtime_arrays, 0, 0, 0, 0, 0, 0, 0)283#error "wrong value for __cpp_runtime_arrays"284#endif285 286#if check(aggregate_nsdmi, 0, 0, 201304, 201304, 201304, 201304, 201304)287#error "wrong value for __cpp_aggregate_nsdmi"288#endif289 290#if check(variable_templates, 0, 0, 201304, 201304, 201304, 201304, 201304)291#error "wrong value for __cpp_variable_templates"292#endif293 294// --- C++11 features ---295 296#if check(unicode_characters, 0, 200704, 200704, 200704, 200704, 200704, 200704)297#error "wrong value for __cpp_unicode_characters"298#endif299 300#if check(raw_strings, 0, 200710, 200710, 200710, 200710, 200710, 200710)301#error "wrong value for __cpp_raw_strings"302#endif303 304#if check(unicode_literals, 0, 200710, 200710, 200710, 200710, 200710, 200710)305#error "wrong value for __cpp_unicode_literals"306#endif307 308#if check(user_defined_literals, 0, 200809, 200809, 200809, 200809, 200809, 200809)309#error "wrong value for __cpp_user_defined_literals"310#endif311 312#if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0, 0, 0, 0) : \313 check(threadsafe_static_init, 200806, 200806, 200806, 200806, 200806, 200806, 200806)314#error "wrong value for __cpp_threadsafe_static_init"315#endif316 317#if check(lambdas, 0, 200907, 200907, 200907, 200907, 200907, 200907)318#error "wrong value for __cpp_lambdas"319#endif320 321#if check(constexpr, 0, 200704, 201304, 201603, 202002, 202211, 202406L)322#error "wrong value for __cpp_constexpr"323#endif324 325#if check(range_based_for, 0, 200907, 200907, 201603, 201603, 202211, 202211)326#error "wrong value for __cpp_range_based_for"327#endif328 329#if check(static_assert, 0, 202306, 202306, 202306, 202306, 202306, 202306)330#error "wrong value for __cpp_static_assert"331#endif332 333#if check(decltype, 0, 200707, 200707, 200707, 200707, 200707, 200707)334#error "wrong value for __cpp_decltype"335#endif336 337#if check(attributes, 0, 200809, 200809, 200809, 200809, 200809, 200809)338#error "wrong value for __cpp_attributes"339#endif340 341#if check(rvalue_references, 0, 200610, 200610, 200610, 200610, 200610, 200610)342#error "wrong value for __cpp_rvalue_references"343#endif344 345#if check(variadic_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704)346#error "wrong value for __cpp_variadic_templates"347#endif348 349#if check(initializer_lists, 0, 200806, 200806, 200806, 200806, 200806, 200806)350#error "wrong value for __cpp_initializer_lists"351#endif352 353#if check(delegating_constructors, 0, 200604, 200604, 200604, 200604, 200604, 200604)354#error "wrong value for __cpp_delegating_constructors"355#endif356 357#if check(nsdmi, 0, 200809, 200809, 200809, 200809, 200809, 200809)358#error "wrong value for __cpp_nsdmi"359#endif360 361#if check(inheriting_constructors, 0, 201511, 201511, 201511, 201511, 201511, 201511)362#error "wrong value for __cpp_inheriting_constructors"363#endif364 365#if check(ref_qualifiers, 0, 200710, 200710, 200710, 200710, 200710, 200710)366#error "wrong value for __cpp_ref_qualifiers"367#endif368 369#if check(alias_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704)370#error "wrong value for __cpp_alias_templates"371#endif372 373// --- C++98 features ---374 375#if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0, 0, 0, 0 ) \376 : check(rtti, 199711, 199711, 199711, 199711, 199711, 199711, 199711)377#error "wrong value for __cpp_rtti"378#endif379 380#if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0, 0, 0, 0) \381 : check(exceptions, 199711, 199711, 199711, 199711, 199711, 199711, 199711)382#error "wrong value for __cpp_exceptions"383#endif384