diff options
Diffstat (limited to 'libcpp/directives.cc')
-rw-r--r-- | libcpp/directives.cc | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 4d06caa..b6dd36a 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -734,13 +734,33 @@ do_undef (cpp_reader *pfile) if (pfile->cb.undef) pfile->cb.undef (pfile, pfile->directive_line, node); + /* Handle -Wkeyword-macro registered identifiers. */ + bool diagnosed = false; + if (CPP_OPTION (pfile, cpp_warn_keyword_macro) + && !CPP_OPTION (pfile, suppress_builtin_macro_warnings) + && cpp_keyword_p (node)) + { + if (CPP_OPTION (pfile, cpp_pedantic) + && CPP_OPTION (pfile, cplusplus) + && CPP_OPTION (pfile, lang) >= CLK_GNUCXX26) + cpp_pedwarning (pfile, CPP_W_KEYWORD_MACRO, + "undefining keyword %qs", NODE_NAME (node)); + else + cpp_warning (pfile, CPP_W_KEYWORD_MACRO, + "undefining keyword %qs", NODE_NAME (node)); + diagnosed = true; + } /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified identifier is not currently defined as a macro name. */ if (cpp_macro_p (node)) { - if (node->flags & NODE_WARN) - cpp_error (pfile, CPP_DL_WARNING, - "undefining %qs", NODE_NAME (node)); + if ((node->flags & NODE_WARN) + && !CPP_OPTION (pfile, suppress_builtin_macro_warnings)) + { + if (!diagnosed) + cpp_error (pfile, CPP_DL_WARNING, + "undefining %qs", NODE_NAME (node)); + } else if (cpp_builtin_macro_p (node) && CPP_OPTION (pfile, warn_builtin_macro_redefined)) cpp_warning (pfile, CPP_W_BUILTIN_MACRO_REDEFINED, @@ -752,6 +772,11 @@ do_undef (cpp_reader *pfile) _cpp_free_definition (node); } + else if ((node->flags & NODE_WARN) + && !CPP_OPTION (pfile, suppress_builtin_macro_warnings) + && !diagnosed + && !cpp_keyword_p (node)) + cpp_error (pfile, CPP_DL_WARNING, "undefining %qs", NODE_NAME (node)); } check_eol (pfile, false); @@ -3070,7 +3095,9 @@ cpp_define (cpp_reader *pfile, const char *str) } buf[count] = '\n'; + CPP_OPTION (pfile, suppress_builtin_macro_warnings) = 1; run_directive (pfile, T_DEFINE, buf, count); + CPP_OPTION (pfile, suppress_builtin_macro_warnings) = 0; } /* Like cpp_define, but does not warn about unused macro. */ @@ -3124,7 +3151,9 @@ _cpp_define_builtin (cpp_reader *pfile, const char *str) char *buf = (char *) alloca (len + 1); memcpy (buf, str, len); buf[len] = '\n'; + CPP_OPTION (pfile, suppress_builtin_macro_warnings) = 1; run_directive (pfile, T_DEFINE, buf, len); + CPP_OPTION (pfile, suppress_builtin_macro_warnings) = 0; } /* Process MACRO as if it appeared as the body of an #undef. */ @@ -3135,7 +3164,9 @@ cpp_undef (cpp_reader *pfile, const char *macro) char *buf = (char *) alloca (len + 1); memcpy (buf, macro, len); buf[len] = '\n'; + CPP_OPTION (pfile, suppress_builtin_macro_warnings) = 1; run_directive (pfile, T_UNDEF, buf, len); + CPP_OPTION (pfile, suppress_builtin_macro_warnings) = 0; } /* Replace a previous definition DEF of the macro STR. If DEF is NULL, |