Hi! We already warn on #undef or pedwarn on #define (but not on #define after #undef) of some builtin macros mentioned in cpp.predefined.
The C++26 P2843R3 paper changes it from (compile time) undefined behavior to ill-formed. The following patch arranges for warning (for #undef) and pedwarn (on #define) for the remaining cpp.predefined macros. __cpp_* feature test macros only for C++20 which added some of them to cpp.predefined, in earlier C++ versions it was just an extension and for pedantic diagnostic I think we don't need to diagnose anything, __STDCPP_* and __cplusplus macros for all C++ versions where they appeared. Unlike the earlier posted -Wkeyword-macro diagnostics (which is done regardless whether the identifier is defined as a macro or not, obviously most likely none of the keywords are defined as macros initially), this one is done like for the remaining older builtin macros and so diagnostics is emitted only if they are defined as macros. As the testcases show, that means we don't diagnose anything on say __STDC_MB_MIGHT_NEQ_WC__ or __STDC_VERSION__ #undef/#define, because we never define those, even when they are mentioned in cpp.predefined, and similarly say __STDCPP_FLOAT16_T__ etc. will not be diagnosed if std::float16_t is not supported. For __cpp_* feature test macros, at least when we implement the full standard for some version we'll be defining all of those. Is that ok like that (and ok that we just warn on #undef of these even with -pedantic-errors; pedantically a warning is a diagnostic as well)? Or do we need to mark as NODE_WARN even nodes for stuff we don't really define when a particular standard version lists them (this would be mainly about those few __STDC* macros conditionally defined or perhaps a few __cpp_* macros that aren't guarded on -std= version but say -fmodules, -fchar8_t, -fcoroutines etc. options) and warn/pedwarn on the libcpp side even when they aren't defined? Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2025-08-02 Jakub Jelinek <ja...@redhat.com> PR preprocessor/120778 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Implement C++26 DR 2581. Add cpp_define_warn lambda and use it. In the if (c_dialect_cxx ()) block with __cpp_* predefinitions add cpp_define lambda. Mark __STDCPP_DEFAULT_NEW_ALIGNMENT__ node as NODE_WARN. Formatting fixes. gcc/ * config/i386/i386-c.cc (ix86_target_macros): Remove NODE_WARN flag from __STDCPP_FLOAT16_T__ and __STDCPP_BFLOAT16_T__ nodes before calling cpp_undefine on those. gcc/testsuite/ * g++.dg/DRs/dr2581-1.C: New test. * g++.dg/DRs/dr2581-2.C: New test. libcpp/ * init.cc (cpp_init_builtins): Mark __cplusplus node as NODE_WARN. --- gcc/c-family/c-cppbuiltin.cc.jj 2025-07-27 23:31:09.084015245 +0200 +++ gcc/c-family/c-cppbuiltin.cc 2025-08-01 12:32:55.838952524 +0200 @@ -913,23 +913,43 @@ c_cpp_builtins (cpp_reader *pfile) /* encoding definitions used by users and libraries */ builtin_define_with_value ("__GNUC_EXECUTION_CHARSET_NAME", - cpp_get_narrow_charset_name (pfile), 1); + cpp_get_narrow_charset_name (pfile), 1); builtin_define_with_value ("__GNUC_WIDE_EXECUTION_CHARSET_NAME", - cpp_get_wide_charset_name (pfile), 1); - + cpp_get_wide_charset_name (pfile), 1); if (c_dialect_cxx ()) - { - int major; - parse_basever (&major, NULL, NULL); - cpp_define_formatted (pfile, "__GNUG__=%d", major); - } + { + int major; + parse_basever (&major, NULL, NULL); + cpp_define_formatted (pfile, "__GNUG__=%d", major); + } /* For stddef.h. They require macros defined in c-common.cc. */ c_stddef_cpp_builtins (); + /* Variant of cpp_define which arranges for diagnostics on user #define + or #undef of the macros. */ + auto cpp_define_warn = [] (cpp_reader *pfile, const char *def) + { + const char *end = strchr (def, '='); + cpp_define (pfile, def); + cpp_lookup (pfile, (const unsigned char *) def, + end ? end - def : strlen (def))->flags |= NODE_WARN; + }; + if (c_dialect_cxx ()) { + /* Treat all cpp_define calls in this block for macros starting + with __cpp_ (for C++20 and later) or __STDCPP_ as cpp_define_warn. */ + auto cpp_define = [=] (cpp_reader *pfile, const char *def) + { + if ((cxx_dialect >= cxx20 && startswith (def, "__cpp_")) + || startswith (def, "__STDCPP_")) + cpp_define_warn (pfile, def); + else + ::cpp_define (pfile, def); + }; + if (flag_weak && SUPPORTS_ONE_ONLY) cpp_define (pfile, "__GXX_WEAK__=1"); else @@ -1123,6 +1143,11 @@ c_cpp_builtins (cpp_reader *pfile) cpp_define (pfile, "__cpp_aligned_new=201606L"); cpp_define_formatted (pfile, "__STDCPP_DEFAULT_NEW_ALIGNMENT__=%d", aligned_new_threshold); + cpp_lookup (pfile, + (const unsigned char *) + "__STDCPP_DEFAULT_NEW_ALIGNMENT__", + sizeof ("__STDCPP_DEFAULT_NEW_ALIGNMENT__") + - 1)->flags |= NODE_WARN; } if (flag_new_ttp) cpp_define (pfile, "__cpp_template_template_args=201611L"); @@ -1292,7 +1317,7 @@ c_cpp_builtins (cpp_reader *pfile) { char name[sizeof ("__STDCPP_FLOAT128_T__=1")]; sprintf (name, "__STDCPP_FLOAT%d_T__=1", floatn_nx_types[i].n); - cpp_define (pfile, name); + cpp_define_warn (pfile, name); } char prefix[20], csuffix[20]; sprintf (prefix, "FLT%d%s", floatn_nx_types[i].n, @@ -1305,7 +1330,7 @@ c_cpp_builtins (cpp_reader *pfile) if (bfloat16_type_node) { if (c_dialect_cxx () && cxx_dialect > cxx20) - cpp_define (pfile, "__STDCPP_BFLOAT16_T__=1"); + cpp_define_warn (pfile, "__STDCPP_BFLOAT16_T__=1"); builtin_define_float_constants ("BFLT16", "BF16", "%s", "BF16", bfloat16_type_node); } --- gcc/config/i386/i386-c.cc.jj 2025-05-19 10:14:35.733853348 +0200 +++ gcc/config/i386/i386-c.cc 2025-08-01 22:49:08.781324718 +0200 @@ -901,7 +901,15 @@ ix86_target_macros (void) { if (c_dialect_cxx () && cxx_dialect > cxx20) { + cpp_lookup (parse_in, + (const unsigned char *) "__STDCPP_FLOAT16_T__", + sizeof ("__STDCPP_FLOAT16_T__") + - 1)->flags &= ~NODE_WARN; cpp_undef (parse_in, "__STDCPP_FLOAT16_T__"); + cpp_lookup (parse_in, + (const unsigned char *) "__STDCPP_BFLOAT16_T__", + sizeof ("__STDCPP_BFLOAT16_T__") + - 1)->flags &= ~NODE_WARN; cpp_undef (parse_in, "__STDCPP_BFLOAT16_T__"); } } --- gcc/testsuite/g++.dg/DRs/dr2581-1.C.jj 2025-08-01 11:25:51.580123393 +0200 +++ gcc/testsuite/g++.dg/DRs/dr2581-1.C 2025-08-01 13:33:06.812236459 +0200 @@ -0,0 +1,110 @@ +// DR 2581 - Undefined behavior for predefined macros +// { dg-do preprocess } +// { dg-additional-options "-fcontracts" { target c++26 } } +// { dg-additional-options "-fmodules -fcoroutines" { target c++20 } } +// { dg-add-options float16 } +// { dg-add-options float32 } +// { dg-add-options float64 } +// { dg-add-options float128 } +// { dg-add-options bfloat16 } + +#undef defined // { dg-error "'defined' cannot be used as a macro name" } +#undef __cplusplus // { dg-warning "undefining '__cplusplus'" } +#undef __DATE__ // { dg-warning "undefining '__DATE__'" } +#undef __FILE__ // { dg-warning "undefining '__FILE__'" } +#undef __LINE__ // { dg-warning "undefining '__LINE__'" } +#undef __STDC_EMBED_NOT_FOUND__ // { dg-warning "undefining '__STDC_EMBED_NOT_FOUND__'" } +#undef __STDC_EMBED_FOUND__ // { dg-warning "undefining '__STDC_EMBED_FOUND__'" } +#undef __STDC_EMBED_EMPTY__ // { dg-warning "undefining '__STDC_EMBED_EMPTY__'" } +#undef __STDC_HOSTED__ // { dg-warning "undefining '__STDC_HOSTED__'" } +#undef __STDCPP_DEFAULT_NEW_ALIGNMENT__ // { dg-warning "undefining '__STDCPP_DEFAULT_NEW_ALIGNMENT__'" "" { target c++17 } } +#undef __STDCPP_FLOAT16_T__ // { dg-warning "undefining '__STDCPP_FLOAT16_T__'" "" { target { c++23 && float16 } } } +#undef __STDCPP_FLOAT32_T__ // { dg-warning "undefining '__STDCPP_FLOAT32_T__'" "" { target { c++23 && float32 } } } +#undef __STDCPP_FLOAT64_T__ // { dg-warning "undefining '__STDCPP_FLOAT64_T__'" "" { target { c++23 && float64 } } } +#undef __STDCPP_FLOAT128_T__ // { dg-warning "undefining '__STDCPP_FLOAT128_T__'" "" { target { c++23 && float128 } } } +#undef __STDCPP_BFLOAT16_T__ // { dg-warning "undefining '__STDCPP_BFLOAT16_T__'" "" { target { c++23 && bfloat16 } } } +#undef __TIME__ // { dg-warning "undefining '__TIME__'" } +#undef __STDC__ // { dg-warning "undefining '__STDC__'" } +#undef __STDC_MB_MIGHT_NEQ_WC__ +#undef __STDC_VERSION__ +#undef __STDC_ISO_10646__ // { dg-warning "undefining '__STDC_ISO_10646__'" } +#undef __STDCPP_THREADS__ // { dg-warning "undefining '__STDCPP_THREADS__'" "" { target c++11 } } +#undef __cpp_aggregate_bases // { dg-warning "undefining '__cpp_aggregate_bases'" "" { target c++20 } } +#undef __cpp_aggregate_nsdmi // { dg-warning "undefining '__cpp_aggregate_nsdmi'" "" { target c++20 } } +#undef __cpp_aggregate_paren_init // { dg-warning "undefining '__cpp_aggregate_paren_init'" "" { target c++20 } } +#undef __cpp_alias_templates // { dg-warning "undefining '__cpp_alias_templates'" "" { target c++20 } } +#undef __cpp_aligned_new // { dg-warning "undefining '__cpp_aligned_new'" "" { target c++20 } } +#undef __cpp_attributes // { dg-warning "undefining '__cpp_attributes'" "" { target c++20 } } +#undef __cpp_auto_cast // { dg-warning "undefining '__cpp_auto_cast'" "" { target c++23 } } +#undef __cpp_binary_literals // { dg-warning "undefining '__cpp_binary_literals'" "" { target c++20 } } +#undef __cpp_capture_star_this // { dg-warning "undefining '__cpp_capture_star_this'" "" { target c++20 } } +#undef __cpp_char8_t // { dg-warning "undefining '__cpp_char8_t'" "" { target c++20 } } +#undef __cpp_concepts // { dg-warning "undefining '__cpp_concepts'" "" { target c++20 } } +#undef __cpp_conditional_explicit // { dg-warning "undefining '__cpp_conditional_explicit'" "" { target c++20 } } +#undef __cpp_constexpr // { dg-warning "undefining '__cpp_constexpr'" "" { target c++20 } } +#undef __cpp_constexpr_dynamic_alloc // { dg-warning "undefining '__cpp_constexpr_dynamic_alloc'" "" { target c++20 } } +#undef __cpp_constexpr_exceptions // { dg-warning "undefining '__cpp_constexpr_exceptions'" "" { target c++26 } } +#undef __cpp_constexpr_in_decltype // { dg-warning "undefining '__cpp_constexpr_in_decltype'" "" { target c++20 } } +#undef __cpp_constexpr_virtual_inheritance // { dg-warning "undefining '__cpp_constexpr_virtual_inheritance'" "" { target c++26 } } +#undef __cpp_consteval // { dg-warning "undefining '__cpp_consteval'" "" { target c++20 } } +#undef __cpp_constinit // { dg-warning "undefining '__cpp_constinit'" "" { target c++20 } } +#undef __cpp_contracts // { dg-warning "undefining '__cpp_contracts'" "" { target c++26 } } +#undef __cpp_decltype // { dg-warning "undefining '__cpp_decltype'" "" { target c++20 } } +#undef __cpp_decltype_auto // { dg-warning "undefining '__cpp_decltype_auto'" "" { target c++20 } } +#undef __cpp_deduction_guides // { dg-warning "undefining '__cpp_deduction_guides'" "" { target c++20 } } +#undef __cpp_delegating_constructors // { dg-warning "undefining '__cpp_delegating_constructors'" "" { target c++20 } } +#undef __cpp_deleted_function // { dg-warning "undefining '__cpp_deleted_function'" "" { target c++26 } } +#undef __cpp_designated_initializers // { dg-warning "undefining '__cpp_designated_initializers'" "" { target c++20 } } +#undef __cpp_enumerator_attributes // { dg-warning "undefining '__cpp_enumerator_attributes'" "" { target c++20 } } +#undef __cpp_expansion_statements +#undef __cpp_explicit_this_parameter // { dg-warning "undefining '__cpp_explicit_this_parameter'" "" { target c++23 } } +#undef __cpp_fold_expressions // { dg-warning "undefining '__cpp_fold_expressions'" "" { target c++20 } } +#undef __cpp_generic_lambdas // { dg-warning "undefining '__cpp_generic_lambdas'" "" { target c++20 } } +#undef __cpp_guaranteed_copy_elision // { dg-warning "undefining '__cpp_guaranteed_copy_elision'" "" { target c++20 } } +#undef __cpp_hex_float // { dg-warning "undefining '__cpp_hex_float'" "" { target c++20 } } +#undef __cpp_if_consteval // { dg-warning "undefining '__cpp_if_consteval'" "" { target c++23 } } +#undef __cpp_if_constexpr // { dg-warning "undefining '__cpp_if_constexpr'" "" { target c++20 } } +#undef __cpp_impl_coroutine // { dg-warning "undefining '__cpp_impl_coroutine'" "" { target c++20 } } +#undef __cpp_impl_destroying_delete // { dg-warning "undefining '__cpp_impl_destroying_delete'" "" { target c++20 } } +#undef __cpp_impl_three_way_comparison // { dg-warning "undefining '__cpp_impl_three_way_comparison'" "" { target c++20 } } +#undef __cpp_impl_reflection +#undef __cpp_implicit_move // { dg-warning "undefining '__cpp_implicit_move'" "" { target c++23 } } +#undef __cpp_inheriting_constructors // { dg-warning "undefining '__cpp_inheriting_constructors'" "" { target c++20 } } +#undef __cpp_init_captures // { dg-warning "undefining '__cpp_init_captures'" "" { target c++20 } } +#undef __cpp_initializer_lists // { dg-warning "undefining '__cpp_initializer_lists'" "" { target c++20 } } +#undef __cpp_inline_variables // { dg-warning "undefining '__cpp_inline_variables'" "" { target c++20 } } +#undef __cpp_lambdas // { dg-warning "undefining '__cpp_lambdas'" "" { target c++20 } } +#undef __cpp_modules // { dg-warning "undefining '__cpp_modules'" "" { target c++20 } } +#undef __cpp_multidimensional_subscript // { dg-warning "undefining '__cpp_multidimensional_subscript'" "" { target c++23 } } +#undef __cpp_named_character_escapes // { dg-warning "undefining '__cpp_named_character_escapes'" "" { target c++23 } } +#undef __cpp_namespace_attributes // { dg-warning "undefining '__cpp_namespace_attributes'" "" { target c++20 } } +#undef __cpp_noexcept_function_type // { dg-warning "undefining '__cpp_noexcept_function_type'" "" { target c++20 } } +#undef __cpp_nontype_template_args // { dg-warning "undefining '__cpp_nontype_template_args'" "" { target c++20 } } +#undef __cpp_nontype_template_parameter_auto // { dg-warning "undefining '__cpp_nontype_template_parameter_auto'" "" { target c++20 } } +#undef __cpp_nsdmi // { dg-warning "undefining '__cpp_nsdmi'" "" { target c++20 } } +#undef __cpp_pack_indexing // { dg-warning "undefining '__cpp_pack_indexing'" "" { target c++26 } } +#undef __cpp_placeholder_variables // { dg-warning "undefining '__cpp_placeholder_variables'" "" { target c++26 } } +#undef __cpp_pp_embed // { dg-warning "undefining '__cpp_pp_embed'" "" { target c++26 } } +#undef __cpp_range_based_for // { dg-warning "undefining '__cpp_range_based_for'" "" { target c++20 } } +#undef __cpp_raw_strings // { dg-warning "undefining '__cpp_raw_strings'" "" { target c++20 } } +#undef __cpp_ref_qualifiers // { dg-warning "undefining '__cpp_ref_qualifiers'" "" { target c++20 } } +#undef __cpp_return_type_deduction // { dg-warning "undefining '__cpp_return_type_deduction'" "" { target c++20 } } +#undef __cpp_rvalue_references // { dg-warning "undefining '__cpp_rvalue_references'" "" { target c++20 } } +#undef __cpp_size_t_suffix // { dg-warning "undefining '__cpp_size_t_suffix'" "" { target c++23 } } +#undef __cpp_sized_deallocation // { dg-warning "undefining '__cpp_sized_deallocation'" "" { target c++20 } } +#undef __cpp_static_assert // { dg-warning "undefining '__cpp_static_assert'" "" { target c++20 } } +#undef __cpp_static_call_operator // { dg-warning "undefining '__cpp_static_call_operator'" "" { target c++23 } } +#undef __cpp_structured_bindings // { dg-warning "undefining '__cpp_structured_bindings'" "" { target c++20 } } +#undef __cpp_template_parameters +#undef __cpp_template_template_args // { dg-warning "undefining '__cpp_template_template_args'" "" { target c++20 } } +#undef __cpp_threadsafe_static_init // { dg-warning "undefining '__cpp_threadsafe_static_init'" "" { target c++20 } } +#undef __cpp_trivial_relocatability // { dg-warning "undefining '__cpp_trivial_relocatability'" "" { target c++26 } } +#undef __cpp_trivial_union +#undef __cpp_unicode_characters // { dg-warning "undefining '__cpp_unicode_characters'" "" { target c++20 } } +#undef __cpp_unicode_literals // { dg-warning "undefining '__cpp_unicode_literals'" "" { target c++20 } } +#undef __cpp_user_defined_literals // { dg-warning "undefining '__cpp_user_defined_literals'" "" { target c++20 } } +#undef __cpp_using_enum // { dg-warning "undefining '__cpp_using_enum'" "" { target c++20 } } +#undef __cpp_variable_templates // { dg-warning "undefining '__cpp_variable_templates'" "" { target c++20 } } +#undef __cpp_variadic_friend // { dg-warning "undefining '__cpp_variadic_friend'" "" { target c++26 } } +#undef __cpp_variadic_templates // { dg-warning "undefining '__cpp_variadic_templates'" "" { target c++20 } } +#undef __cpp_variadic_using // { dg-warning "undefining '__cpp_variadic_using'" "" { target c++20 } } --- gcc/testsuite/g++.dg/DRs/dr2581-2.C.jj 2025-08-01 12:39:17.286915621 +0200 +++ gcc/testsuite/g++.dg/DRs/dr2581-2.C 2025-08-01 13:33:25.328991785 +0200 @@ -0,0 +1,110 @@ +// DR 2581 - Undefined behavior for predefined macros +// { dg-do preprocess } +// { dg-additional-options "-fcontracts" { target c++26 } } +// { dg-additional-options "-fmodules -fcoroutines" { target c++20 } } +// { dg-add-options float16 } +// { dg-add-options float32 } +// { dg-add-options float64 } +// { dg-add-options float128 } +// { dg-add-options bfloat16 } + +#define defined defined // { dg-error "'defined' cannot be used as a macro name" } +#define __cplusplus 202400L // { dg-error "'__cplusplus' redefined" } +#define __DATE__ // { dg-error "'__DATE__' redefined" } +#define __FILE__ // { dg-error "'__FILE__' redefined" } +#define __LINE__ // { dg-error "'__LINE__' redefined" } +#define __STDC_EMBED_NOT_FOUND__ 0 // { dg-error "'__STDC_EMBED_NOT_FOUND__' redefined" } +#define __STDC_EMBED_FOUND__ 1 // { dg-error "'__STDC_EMBED_FOUND__' redefined" } +#define __STDC_EMBED_EMPTY__ 2 // { dg-error "'__STDC_EMBED_EMPTY__' redefined" } +#define __STDC_HOSTED__ 1 // { dg-error "'__STDC_HOSTED__' redefined" } +#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 1 // { dg-error "'__STDCPP_DEFAULT_NEW_ALIGNMENT__' redefined" "" { target c++17 } } +#define __STDCPP_FLOAT16_T__ 1 // { dg-error "'__STDCPP_FLOAT16_T__' redefined" "" { target { c++23 && float16 } } } +#define __STDCPP_FLOAT32_T__ 1 // { dg-error "'__STDCPP_FLOAT32_T__' redefined" "" { target { c++23 && float32 } } } +#define __STDCPP_FLOAT64_T__ 1 // { dg-error "'__STDCPP_FLOAT64_T__' redefined" "" { target { c++23 && float64 } } } +#define __STDCPP_FLOAT128_T__ 1 // { dg-error "'__STDCPP_FLOAT128_T__' redefined" "" { target { c++23 && float128 } } } +#define __STDCPP_BFLOAT16_T__ 1 // { dg-error "'__STDCPP_BFLOAT16_T__' redefined" "" { target { c++23 && bfloat16 } } } +#define __TIME__ // { dg-error "'__TIME__' redefined" } +#define __STDC__ // { dg-error "'__STDC__' redefined" } +#define __STDC_MB_MIGHT_NEQ_WC__ +#define __STDC_VERSION__ +#define __STDC_ISO_10646__ // { dg-error "'__STDC_ISO_10646__' redefined" } +#define __STDCPP_THREADS__ // { dg-error "'__STDCPP_THREADS__' redefined" "" { target c++11 } } +#define __cpp_aggregate_bases 201603L // { dg-error "'__cpp_aggregate_bases' redefined" "" { target c++20 } } +#define __cpp_aggregate_nsdmi 201304L // { dg-error "'__cpp_aggregate_nsdmi' redefined" "" { target c++20 } } +#define __cpp_aggregate_paren_init 201902L // { dg-error "'__cpp_aggregate_paren_init' redefined" "" { target c++20 } } +#define __cpp_alias_templates 200704L // { dg-error "'__cpp_alias_templates' redefined" "" { target c++20 } } +#define __cpp_aligned_new 201606L // { dg-error "'__cpp_aligned_new' redefined" "" { target c++20 } } +#define __cpp_attributes 200809L // { dg-error "'__cpp_attributes' redefined" "" { target c++20 } } +#define __cpp_auto_cast 202110L // { dg-error "'__cpp_auto_cast' redefined" "" { target c++23 } } +#define __cpp_binary_literals 201304L // { dg-error "'__cpp_binary_literals' redefined" "" { target c++20 } } +#define __cpp_capture_star_this 201603L // { dg-error "'__cpp_capture_star_this' redefined" "" { target c++20 } } +#define __cpp_char8_t 202207L // { dg-error "'__cpp_char8_t' redefined" "" { target c++20 } } +#define __cpp_concepts 202002L // { dg-error "'__cpp_concepts' redefined" "" { target c++20 } } +#define __cpp_conditional_explicit 201806L // { dg-error "'__cpp_conditional_explicit' redefined" "" { target c++20 } } +#define __cpp_constexpr 202406L // { dg-error "'__cpp_constexpr' redefined" "" { target c++11 } } +#define __cpp_constexpr_dynamic_alloc 201907L // { dg-error "'__cpp_constexpr_dynamic_alloc' redefined" "" { target c++20 } } +#define __cpp_constexpr_exceptions 202411L // { dg-error "'__cpp_constexpr_exceptions' redefined" "" { target c++26 } } +#define __cpp_constexpr_in_decltype 201711L // { dg-error "'__cpp_constexpr_in_decltype' redefined" "" { target c++20 } } +#define __cpp_constexpr_virtual_inheritance 202506L // { dg-error "'__cpp_constexpr_virtual_inheritance' redefined" "" { target c++26 } } +#define __cpp_consteval 202211L // { dg-error "'__cpp_consteval' redefined" "" { target c++20 } } +#define __cpp_constinit 201907L // { dg-error "'__cpp_constinit' redefined" "" { target c++20 } } +#define __cpp_contracts 202502L // { dg-error "'__cpp_contracts' redefined" "" { target c++26 } } +#define __cpp_decltype 200707L // { dg-error "'__cpp_decltype' redefined" "" { target c++20 } } +#define __cpp_decltype_auto 201304L // { dg-error "'__cpp_decltype_auto' redefined" "" { target c++20 } } +#define __cpp_deduction_guides 201907L // { dg-error "'__cpp_deduction_guides' redefined" "" { target c++17 } } +#define __cpp_delegating_constructors 200604L // { dg-error "'__cpp_delegating_constructors' redefined" "" { target c++20 } } +#define __cpp_deleted_function 202403L // { dg-error "'__cpp_deleted_function' redefined" "" { target c++26 } } +#define __cpp_designated_initializers 201707L // { dg-error "'__cpp_designated_initializers' redefined" "" { target c++20 } } +#define __cpp_enumerator_attributes 201411L // { dg-error "'__cpp_enumerator_attributes' redefined" "" { target c++20 } } +#define __cpp_expansion_statements 202506L +#define __cpp_explicit_this_parameter 202110L // { dg-error "'__cpp_explicit_this_parameter' redefined" "" { target c++23 } } +#define __cpp_fold_expressions 201603L // { dg-error "'__cpp_fold_expressions' redefined" "" { target c++20 } } +#define __cpp_generic_lambdas 201707L // { dg-error "'__cpp_generic_lambdas' redefined" "" { target c++14 } } +#define __cpp_guaranteed_copy_elision 201606L // { dg-error "'__cpp_guaranteed_copy_elision' redefined" "" { target c++20 } } +#define __cpp_hex_float 201603L // { dg-error "'__cpp_hex_float' redefined" "" { target c++20 } } +#define __cpp_if_consteval 202106L // { dg-error "'__cpp_if_consteval' redefined" "" { target c++23 } } +#define __cpp_if_constexpr 201606L // { dg-error "'__cpp_if_constexpr' redefined" "" { target c++20 } } +#define __cpp_impl_coroutine 201902L // { dg-error "'__cpp_impl_coroutine' redefined" "" { target c++20 } } +#define __cpp_impl_destroying_delete 201806L // { dg-error "'__cpp_impl_destroying_delete' redefined" "" { target c++20 } } +#define __cpp_impl_three_way_comparison 201907L // { dg-error "'__cpp_impl_three_way_comparison' redefined" "" { target c++20 } } +#define __cpp_impl_reflection 202506L +#define __cpp_implicit_move 202207L // { dg-error "'__cpp_implicit_move' redefined" "" { target c++23 } } +#define __cpp_inheriting_constructors 201511L // { dg-error "'__cpp_inheriting_constructors' redefined" "" { target c++20 } } +#define __cpp_init_captures 201803L // { dg-error "'__cpp_init_captures' redefined" "" { target c++14 } } +#define __cpp_initializer_lists 200806L // { dg-error "'__cpp_initializer_lists' redefined" "" { target c++20 } } +#define __cpp_inline_variables 201606L // { dg-error "'__cpp_inline_variables' redefined" "" { target c++20 } } +#define __cpp_lambdas 200907L // { dg-error "'__cpp_lambdas' redefined" "" { target c++20 } } +#define __cpp_modules 201907L // { dg-error "'__cpp_modules' redefined" "" { target c++20 } } +#define __cpp_multidimensional_subscript 202211L // { dg-error "'__cpp_multidimensional_subscript' redefined" "" { target c++23 } } +#define __cpp_named_character_escapes 202207L // { dg-error "'__cpp_named_character_escapes' redefined" "" { target c++23 } } +#define __cpp_namespace_attributes 201411L // { dg-error "'__cpp_namespace_attributes' redefined" "" { target c++20 } } +#define __cpp_noexcept_function_type 201510L // { dg-error "'__cpp_noexcept_function_type' redefined" "" { target c++20 } } +#define __cpp_nontype_template_args 201911L // { dg-error "'__cpp_nontype_template_args' redefined" "" { target c++17 } } +#define __cpp_nontype_template_parameter_auto 201606L // { dg-error "'__cpp_nontype_template_parameter_auto' redefined" "" { target c++20 } } +#define __cpp_nsdmi 200809L // { dg-error "'__cpp_nsdmi' redefined" "" { target c++20 } } +#define __cpp_pack_indexing 202311L // { dg-error "'__cpp_pack_indexing' redefined" "" { target c++26 } } +#define __cpp_placeholder_variables 202306L // { dg-error "'__cpp_placeholder_variables' redefined" "" { target c++26 } } +#define __cpp_pp_embed 202502L // { dg-error "'__cpp_pp_embed' redefined" "" { target c++26 } } +#define __cpp_range_based_for 202211L // { dg-error "'__cpp_range_based_for' redefined" "" { target c++11 } } +#define __cpp_raw_strings 200710L // { dg-error "'__cpp_raw_strings' redefined" "" { target c++20 } } +#define __cpp_ref_qualifiers 200710L // { dg-error "'__cpp_ref_qualifiers' redefined" "" { target c++20 } } +#define __cpp_return_type_deduction 201304L // { dg-error "'__cpp_return_type_deduction' redefined" "" { target c++20 } } +#define __cpp_rvalue_references 200610L // { dg-error "'__cpp_rvalue_references' redefined" "" { target c++20 } } +#define __cpp_size_t_suffix 202011L // { dg-error "'__cpp_size_t_suffix' redefined" "" { target c++23 } } +#define __cpp_sized_deallocation 201309L // { dg-error "'__cpp_sized_deallocation' redefined" "" { target c++20 } } +#define __cpp_static_assert 202306L // { dg-error "'__cpp_static_assert' redefined" "" { target c++11 } } +#define __cpp_static_call_operator 202207L // { dg-error "'__cpp_static_call_operator' redefined" "" { target c++23 } } +#define __cpp_structured_bindings 202411L // { dg-error "'__cpp_structured_bindings' redefined" "" { target c++17 } } +#define __cpp_template_parameters 202502L +#define __cpp_template_template_args 201611L // { dg-error "'__cpp_template_template_args' redefined" "" { target c++20 } } +#define __cpp_threadsafe_static_init 200806L // { dg-error "'__cpp_threadsafe_static_init' redefined" "" { target c++20 } } +#define __cpp_trivial_relocatability 202502L // { dg-error "'__cpp_trivial_relocatability' redefined" "" { target c++26 } } +#define __cpp_trivial_union 202502L +#define __cpp_unicode_characters 200704L // { dg-error "'__cpp_unicode_characters' redefined" "" { target c++17 } } +#define __cpp_unicode_literals 200710L // { dg-error "'__cpp_unicode_literals' redefined" "" { target c++20 } } +#define __cpp_user_defined_literals 200809L // { dg-error "'__cpp_user_defined_literals' redefined" "" { target c++20 } } +#define __cpp_using_enum 201907L // { dg-error "'__cpp_using_enum' redefined" "" { target c++20 } } +#define __cpp_variable_templates 201304L // { dg-error "'__cpp_variable_templates' redefined" "" { target c++20 } } +#define __cpp_variadic_friend 202403L // { dg-error "'__cpp_variadic_friend' redefined" "" { target c++26 } } +#define __cpp_variadic_templates 200704L // { dg-error "'__cpp_variadic_templates' redefined" "" { target c++20 } } +#define __cpp_variadic_using 201611L // { dg-error "'__cpp_variadic_using' redefined" "" { target c++20 } } --- libcpp/init.cc.jj 2025-04-08 14:09:47.170503397 +0200 +++ libcpp/init.cc 2025-08-01 13:32:18.121879820 +0200 @@ -618,6 +618,8 @@ cpp_init_builtins (cpp_reader *pfile, in _cpp_define_builtin (pfile, "__cplusplus 201103L"); else _cpp_define_builtin (pfile, "__cplusplus 199711L"); + cpp_lookup (pfile, (const unsigned char *) "__cplusplus", + sizeof ("__cplusplus") - 1)->flags |= NODE_WARN; } else if (CPP_OPTION (pfile, lang) == CLK_ASM) _cpp_define_builtin (pfile, "__ASSEMBLER__ 1"); Jakub