mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 03:46:53 -05:00
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.
This commit is contained in:
@@ -1856,11 +1856,12 @@ skip_whitespace (cpp_reader *pfile, cppchar_t c)
|
||||
/* Just \f \v or \0 left. */
|
||||
else if (c == '\0')
|
||||
saw_NUL = true;
|
||||
else if (pfile->state.in_directive && CPP_PEDANTIC (pfile))
|
||||
cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line_table->highest_line,
|
||||
CPP_BUF_COL (buffer),
|
||||
"%s in preprocessing directive",
|
||||
c == '\f' ? "form feed" : "vertical tab");
|
||||
else if (pfile->state.in_directive)
|
||||
cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
|
||||
pfile->line_table->highest_line,
|
||||
CPP_BUF_COL (buffer),
|
||||
"%s in preprocessing directive",
|
||||
c == '\f' ? "form feed" : "vertical tab");
|
||||
|
||||
c = *buffer->cur++;
|
||||
}
|
||||
@@ -2026,11 +2027,11 @@ maybe_va_opt_error (cpp_reader *pfile)
|
||||
if (!_cpp_in_system_header (pfile))
|
||||
{
|
||||
if (CPP_OPTION (pfile, cplusplus))
|
||||
cpp_error (pfile, CPP_DL_PEDWARN,
|
||||
"__VA_OPT__ is not available until C++20");
|
||||
cpp_pedwarning (pfile, CPP_W_CXX20_EXTENSIONS,
|
||||
"__VA_OPT__ is not available until C++20");
|
||||
else
|
||||
cpp_error (pfile, CPP_DL_PEDWARN,
|
||||
"__VA_OPT__ is not available until C23");
|
||||
cpp_pedwarning (pfile, CPP_W_PEDANTIC,
|
||||
"__VA_OPT__ is not available until C23");
|
||||
}
|
||||
}
|
||||
else if (!pfile->state.va_args_ok)
|
||||
@@ -3903,8 +3904,9 @@ _cpp_lex_direct (cpp_reader *pfile)
|
||||
&& CPP_PEDANTIC (pfile)
|
||||
&& ! buffer->warned_cplusplus_comments)
|
||||
{
|
||||
if (cpp_error (pfile, CPP_DL_PEDWARN,
|
||||
"C++ style comments are not allowed in ISO C90"))
|
||||
if (cpp_pedwarning (pfile, CPP_W_PEDANTIC,
|
||||
"C++ style comments are not allowed "
|
||||
"in ISO C90"))
|
||||
cpp_error (pfile, CPP_DL_NOTE,
|
||||
"(this will be reported only once per input file)");
|
||||
buffer->warned_cplusplus_comments = 1;
|
||||
|
||||
Reference in New Issue
Block a user