aboutsummaryrefslogtreecommitdiff
path: root/libcpp/directives.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/directives.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/directives.cc')
-rw-r--r--libcpp/directives.cc78
1 files changed, 44 insertions, 34 deletions
diff --git a/libcpp/directives.cc b/libcpp/directives.cc
index f8d9898..859cd04 100644
--- a/libcpp/directives.cc
+++ b/libcpp/directives.cc
@@ -383,28 +383,37 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented)
-pedantic take precedence if both are applicable. */
if (! pfile->state.skipping)
{
+ bool warned = false;
if (dir->origin == EXTENSION
- && !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc))
- && CPP_PEDANTIC (pfile))
- cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name);
- else if (dir == &dtable[T_WARNING])
+ && !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc)))
+ warned
+ = cpp_pedwarning (pfile, CPP_W_PEDANTIC, "#%s is a GCC extension",
+ dir->name);
+ if (!warned && dir == &dtable[T_WARNING])
{
if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, warning_directive))
{
if (CPP_OPTION (pfile, cplusplus))
- cpp_error (pfile, CPP_DL_PEDWARN,
- "#%s before C++23 is a GCC extension", dir->name);
+ warned
+ = cpp_pedwarning (pfile, CPP_W_CXX23_EXTENSIONS,
+ "#%s before C++23 is a GCC extension",
+ dir->name);
else
- cpp_error (pfile, CPP_DL_PEDWARN,
- "#%s before C23 is a GCC extension", dir->name);
+ warned
+ = cpp_pedwarning (pfile, CPP_W_PEDANTIC,
+ "#%s before C23 is a GCC extension",
+ dir->name);
}
- else if (CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
- cpp_warning (pfile, CPP_W_C11_C23_COMPAT,
- "#%s before C23 is a GCC extension", dir->name);
+
+ if (!warned && CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
+ warned = cpp_warning (pfile, CPP_W_C11_C23_COMPAT,
+ "#%s before C23 is a GCC extension",
+ dir->name);
}
- else if (((dir->flags & DEPRECATED) != 0
- || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc)))
- && CPP_OPTION (pfile, cpp_warn_deprecated))
+
+ if (((dir->flags & DEPRECATED) != 0
+ || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc)))
+ && !warned)
cpp_warning (pfile, CPP_W_DEPRECATED,
"#%s is a deprecated GCC extension", dir->name);
}
@@ -450,9 +459,9 @@ _cpp_handle_directive (cpp_reader *pfile, bool indented)
if (was_parsing_args)
{
- if (CPP_OPTION (pfile, cpp_pedantic))
- cpp_error (pfile, CPP_DL_PEDWARN,
- "embedding a directive within macro arguments is not portable");
+ cpp_pedwarning (pfile, CPP_W_PEDANTIC,
+ "embedding a directive within macro arguments is not "
+ "portable");
pfile->state.parsing_args = 0;
pfile->state.prevent_expansion = 0;
}
@@ -477,10 +486,10 @@ _cpp_handle_directive (cpp_reader *pfile, bool indented)
else if (dname->type == CPP_NUMBER && CPP_OPTION (pfile, lang) != CLK_ASM)
{
dir = &linemarker_dir;
- if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, preprocessed)
+ if (! CPP_OPTION (pfile, preprocessed)
&& ! pfile->state.skipping)
- cpp_error (pfile, CPP_DL_PEDWARN,
- "style of line directive is a GCC extension");
+ cpp_pedwarning (pfile, CPP_W_PEDANTIC,
+ "style of line directive is a GCC extension");
}
if (dir)
@@ -1388,8 +1397,9 @@ do_line (cpp_reader *pfile)
return;
}
- if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap || wrapped))
- cpp_error (pfile, CPP_DL_PEDWARN, "line number out of range");
+ if ((new_lineno == 0 || new_lineno > cap || wrapped)
+ && cpp_pedwarning (pfile, CPP_W_PEDANTIC, "line number out of range"))
+ ;
else if (wrapped)
cpp_error (pfile, CPP_DL_WARNING, "line number out of range");
@@ -2531,13 +2541,13 @@ do_elif (cpp_reader *pfile)
&& !pfile->state.skipping)
{
if (CPP_OPTION (pfile, cplusplus))
- cpp_error (pfile, CPP_DL_PEDWARN,
- "#%s before C++23 is a GCC extension",
- pfile->directive->name);
+ cpp_pedwarning (pfile, CPP_W_CXX23_EXTENSIONS,
+ "#%s before C++23 is a GCC extension",
+ pfile->directive->name);
else
- cpp_error (pfile, CPP_DL_PEDWARN,
- "#%s before C23 is a GCC extension",
- pfile->directive->name);
+ cpp_pedwarning (pfile, CPP_W_PEDANTIC,
+ "#%s before C23 is a GCC extension",
+ pfile->directive->name);
}
pfile->state.skipping = 1;
}
@@ -2570,13 +2580,13 @@ do_elif (cpp_reader *pfile)
&& pfile->state.skipping != skip)
{
if (CPP_OPTION (pfile, cplusplus))
- cpp_error (pfile, CPP_DL_PEDWARN,
- "#%s before C++23 is a GCC extension",
- pfile->directive->name);
+ cpp_pedwarning (pfile, CPP_W_CXX23_EXTENSIONS,
+ "#%s before C++23 is a GCC extension",
+ pfile->directive->name);
else
- cpp_error (pfile, CPP_DL_PEDWARN,
- "#%s before C23 is a GCC extension",
- pfile->directive->name);
+ cpp_pedwarning (pfile, CPP_W_PEDANTIC,
+ "#%s before C23 is a GCC extension",
+ pfile->directive->name);
}
pfile->state.skipping = skip;
}