On 8/15/25 1:35 AM, Jakub Jelinek wrote:
On Thu, Aug 14, 2025 at 01:32:18PM -0400, Jason Merrill wrote:
Could we suppress warnings for all builtin_define instead of specifically
for these names?

Ok, done for cpp_define/_cpp_define_builtin/cpp_undef now, so neither
the rs6000-c.cc patch nor changes in i386-c.cc are needed.

On Thu, Aug 14, 2025 at 01:40:26PM -0400, Jason Merrill wrote:
Maybe the cpp_warn lambda from c-cppbuiltin above should be an inline
function in cpplib.h?  Perhaps taking an optional boolean to cover the
i386-c.cc use as well?

Added as 2 overloads (one with explicit length, one without) and used them
also in the -Wkeyword-macro setup etc.  As the i386-c.cc and rs6000-c.cc
changes aren't needed anymore, there is no need for clearing of NODE_WARN
bits, all we need is to set it.

So far lightly tested on x86_64-linux and powerpc64le-linux, ok for trunk
if it passes bootstrap/regtest?

2025-08-15  Jakub Jelinek  <ja...@redhat.com>

        PR preprocessor/120778
        PR target/121520
gcc/c-family/
        * c-cppbuiltin.cc (c_cpp_builtins): Implement C++26 DR 2581.  Add
        cpp_define_warn lambda and use it as well as cpp_warn where needed.
        In the if (c_dialect_cxx ()) block with __cpp_* predefinitions add
        cpp_define lambda.  Formatting fixes.
gcc/c/
        * c-decl.cc (c_init_decl_processing): Use cpp_warn instead of
        cpp_lookup and NODE_WARN bit setting.
gcc/cp/
        * lex.cc (cxx_init): Remove warn_on lambda.  Use cpp_warn instead of
        cpp_lookup and NODE_WARN bit setting or warn_on.
gcc/testsuite/
        * g++.dg/DRs/dr2581-1.C: New test.
        * g++.dg/DRs/dr2581-2.C: New test.
        * c-c++-common/cpp/pr92296-2.c: Expect warnings also on defining
        special macros after undefining them.
libcpp/
        * include/cpplib.h (struct cpp_options): Add warn_builtin_macros
        member.
        (cpp_warn): New inline functions.
        * init.cc (cpp_create_reader): Set warn_builtin_macros.

This name is confusing wrt warn_builtin_macro_redefined; since it seems to be used internally to suppress the warning, maybe call it suppress_builtin_macro_warning? Or allow_... if you don't want to reverse the sense?

@@ -3412,8 +3412,11 @@ warn_of_redefinition (cpp_reader *pfile, cpp_hashnode 
*node,
    /* Some redefinitions need to be warned about regardless.  */
    if (node->flags & NODE_WARN)
      {
-      /* Ignore NODE_WARN on -Wkeyword-macro registered identifiers though.  */
-      if (!CPP_OPTION (pfile, cpp_warn_keyword_macro) || !cpp_keyword_p (node))
+      /* Ignore NODE_WARN on -Wkeyword-macro registered identifiers though
+        or during cpp_define.  */
+      if (CPP_OPTION (pfile, warn_builtin_macros)

Don't we also want to return early if warn_builtin_macros is unset (modulo renaming/reversing)?

+         && (!CPP_OPTION (pfile, cpp_warn_keyword_macro)
+             || !cpp_keyword_p (node)))
        return true;
      }

Jason

Reply via email to