diff options
author | Jason Merrill <jason@redhat.com> | 2024-08-27 13:15:16 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-09-12 11:29:38 -0400 |
commit | c5009eb887910271ea35a857aa68941c7227b9c7 (patch) | |
tree | 1e6366fb3fbc3eb1c443c611fc95511cd685043d /libcpp/macro.cc | |
parent | 9a94c8ffdc8b554a2d95e0101e96830efee58add (diff) | |
download | gcc-c5009eb887910271ea35a857aa68941c7227b9c7.zip gcc-c5009eb887910271ea35a857aa68941c7227b9c7.tar.gz gcc-c5009eb887910271ea35a857aa68941c7227b9c7.tar.bz2 |
libcpp: adjust pedwarn handling
Using cpp_pedwarning (CPP_W_PEDANTIC instead of if (CPP_PEDANTIC cpp_error
lets users suppress these diagnostics with
#pragma GCC diagnostic ignored "-Wpedantic".
This patch changes all instances of the cpp_error (CPP_DL_PEDWARN to
cpp_pedwarning. In cases where the extension appears in a later C++
revision, we now condition the warning on the relevant -Wc++??-extensions
flag instead of -Wpedantic; in such cases often the if (CPP_PEDANTIC) check
is retained to preserve the default non-warning behavior.
I didn't attempt to adjust the warning flags for the C compiler, since it
seems to follow a different system than C++.
The CPP_PEDANTIC check is also kept in _cpp_lex_direct to avoid an ICE in
the self-tests from cb.diagnostics not being initialized.
While working on testcases for these changes I noticed that the c-c++-common
tests are not run with -pedantic-errors by default like the gcc.dg and
g++.dg directories are. And if I specify -pedantic-errors with dg-options,
the default -std= changes from c++?? to gnu++??, which interferes with some
other pedwarns. So two of the tests are C++-only.
libcpp/ChangeLog:
* include/cpplib.h (enum cpp_warning_reason): Add
CPP_W_CXX{14,17,20,23}_EXTENSIONS.
* charset.cc (_cpp_valid_ucn, convert_hex, convert_oct)
(convert_escape, narrow_str_to_charconst): Use cpp_pedwarning
instead of cpp_error for pedwarns.
* directives.cc (directive_diagnostics, _cpp_handle_directive)
(do_line, do_elif): Likewise.
* expr.cc (cpp_classify_number, eval_token): Likewise.
* lex.cc (skip_whitespace, maybe_va_opt_error)
(_cpp_lex_direct): Likewise.
* macro.cc (_cpp_arguments_ok): Likewise.
(replace_args): Use -Wvariadic-macros for pedwarn about
empty macro arguments.
gcc/c-family/ChangeLog:
* c.opt: Add CppReason for Wc++{14,17,20,23}-extensions.
* c-pragma.cc (handle_pragma_diagnostic_impl): Don't check
OPT_Wc__23_extensions.
gcc/testsuite/ChangeLog:
* c-c++-common/pragma-diag-17.c: New test.
* g++.dg/cpp0x/va-opt1.C: New test.
* g++.dg/cpp23/named-universal-char-escape3.C: New test.
Diffstat (limited to 'libcpp/macro.cc')
-rw-r--r-- | libcpp/macro.cc | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libcpp/macro.cc b/libcpp/macro.cc index dbb9925..f679b6a 100644 --- a/libcpp/macro.cc +++ b/libcpp/macro.cc @@ -1196,13 +1196,13 @@ _cpp_arguments_ok (cpp_reader *pfile, cpp_macro *macro, const cpp_hashnode *node && ! CPP_OPTION (pfile, va_opt)) { if (CPP_OPTION (pfile, cplusplus)) - cpp_error (pfile, CPP_DL_PEDWARN, - "ISO C++11 requires at least one argument " - "for the \"...\" in a variadic macro"); + cpp_pedwarning (pfile, CPP_W_CXX20_EXTENSIONS, + "ISO C++11 requires at least one argument " + "for the \"...\" in a variadic macro"); else - cpp_error (pfile, CPP_DL_PEDWARN, - "ISO C99 requires at least one argument " - "for the \"...\" in a variadic macro"); + cpp_pedwarning (pfile, CPP_W_PEDANTIC, + "ISO C99 requires at least one argument " + "for the \"...\" in a variadic macro"); } return true; } @@ -2391,7 +2391,7 @@ replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, && ! macro->syshdr && ! _cpp_in_system_header (pfile)) { if (CPP_OPTION (pfile, cplusplus)) - cpp_pedwarning (pfile, CPP_W_PEDANTIC, + cpp_pedwarning (pfile, CPP_W_VARIADIC_MACROS, "invoking macro %s argument %d: " "empty macro arguments are undefined" " in ISO C++98", |