aboutsummaryrefslogtreecommitdiff
path: root/libcpp/expr.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-08-27 13:15:16 -0400
committerJason Merrill <jason@redhat.com>2024-09-12 11:29:38 -0400
commitc5009eb887910271ea35a857aa68941c7227b9c7 (patch)
tree1e6366fb3fbc3eb1c443c611fc95511cd685043d /libcpp/expr.cc
parent9a94c8ffdc8b554a2d95e0101e96830efee58add (diff)
downloadgcc-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/expr.cc')
-rw-r--r--libcpp/expr.cc77
1 files changed, 44 insertions, 33 deletions
diff --git a/libcpp/expr.cc b/libcpp/expr.cc
index 3202d8e..089bf3e 100644
--- a/libcpp/expr.cc
+++ b/libcpp/expr.cc
@@ -662,9 +662,9 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
if (radix == 8)
radix = 10;
- if (CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "fixed-point constants are a GCC extension");
+ cpp_pedwarning_with_line
+ (pfile, CPP_W_PEDANTIC, virtual_location, 0,
+ "fixed-point constants are a GCC extension");
goto syntax_ok;
}
else
@@ -701,11 +701,13 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
&& !CPP_OPTION (pfile, extended_numbers))
{
if (CPP_OPTION (pfile, cplusplus))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "use of C++17 hexadecimal floating constant");
+ cpp_pedwarning_with_line (pfile, CPP_W_CXX17_EXTENSIONS,
+ virtual_location, 0, "use of C++17 "
+ "hexadecimal floating constant");
else
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "use of C99 hexadecimal floating constant");
+ cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
+ virtual_location, 0, "use of C99 "
+ "hexadecimal floating constant");
}
if (float_flag == AFTER_EXPON)
@@ -766,9 +768,10 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
/* A suffix for double is a GCC extension via decimal float support.
If the suffix also specifies an imaginary value we'll catch that
later. */
- if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "suffix for double constant is a GCC extension");
+ if (result == CPP_N_MEDIUM)
+ cpp_pedwarning_with_line
+ (pfile, CPP_W_PEDANTIC, virtual_location, 0,
+ "suffix for double constant is a GCC extension");
/* Radix must be 10 for decimal floats. */
if ((result & CPP_N_DFLOAT) && radix != 10)
@@ -779,15 +782,16 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
return CPP_N_INVALID;
}
- if ((result & (CPP_N_FRACT | CPP_N_ACCUM)) && CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "fixed-point constants are a GCC extension");
+ if (result & (CPP_N_FRACT | CPP_N_ACCUM))
+ cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0,
+ "fixed-point constants are a GCC extension");
if (result & CPP_N_DFLOAT)
{
- if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, dfp_constants))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "decimal float constants are a C23 feature");
+ if (!CPP_OPTION (pfile, dfp_constants))
+ cpp_pedwarning_with_line
+ (pfile, CPP_W_PEDANTIC, virtual_location, 0,
+ "decimal float constants are a C23 feature");
else if (CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT,
virtual_location, 0,
@@ -870,12 +874,12 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT,
virtual_location, 0, message);
}
- else if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, true_false))
+ else if (!CPP_OPTION (pfile, true_false))
{
const char *message = N_("ISO C does not support literal "
"%<wb%> suffixes before C23");
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- message);
+ cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
+ virtual_location, 0, message);
}
}
@@ -883,20 +887,27 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token,
}
syntax_ok:
- if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- "imaginary constants are a GCC extension");
+ if (result & CPP_N_IMAGINARY)
+ cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0,
+ "imaginary constants are a GCC extension");
if (radix == 2)
{
+ bool warned = false;
if (!CPP_OPTION (pfile, binary_constants)
&& CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0,
- CPP_OPTION (pfile, cplusplus)
- ? N_("binary constants are a C++14 feature "
- "or GCC extension")
- : N_("binary constants are a C23 feature "
- "or GCC extension"));
- else if (CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
+ {
+ if (CPP_OPTION (pfile, cplusplus))
+ warned
+ = (cpp_pedwarning_with_line
+ (pfile, CPP_W_CXX14_EXTENSIONS, virtual_location, 0,
+ "binary constants are a C++14 feature or GCC extension"));
+ else
+ warned
+ = (cpp_pedwarning_with_line
+ (pfile, CPP_W_PEDANTIC, virtual_location, 0,
+ "binary constants are a C23 feature or GCC extension"));
+ }
+ if (!warned && CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT,
virtual_location, 0,
"binary constants are a C23 feature");
@@ -1267,10 +1278,10 @@ eval_token (cpp_reader *pfile, const cpp_token *token,
{
/* A pedantic warning takes precedence over a deprecated
warning here. */
- if (CPP_PEDANTIC (pfile))
- cpp_error_with_line (pfile, CPP_DL_PEDWARN,
- virtual_location, 0,
- "assertions are a GCC extension");
+ if (cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC,
+ virtual_location, 0,
+ "assertions are a GCC extension"))
+ ;
else if (CPP_OPTION (pfile, cpp_warn_deprecated))
cpp_warning_with_line (pfile, CPP_W_DEPRECATED, virtual_location, 0,
"assertions are a deprecated extension");