aboutsummaryrefslogtreecommitdiff
path: root/gcc
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 /gcc
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 'gcc')
-rw-r--r--gcc/c-family/c-pragma.cc2
-rw-r--r--gcc/c-family/c.opt8
-rw-r--r--gcc/testsuite/c-c++-common/pragma-diag-17.c25
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/va-opt1.C18
-rw-r--r--gcc/testsuite/g++.dg/cpp23/named-universal-char-escape3.C19
5 files changed, 66 insertions, 6 deletions
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index bb867eb..ed2a7a0 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -964,8 +964,6 @@ handle_pragma_diagnostic_impl ()
unsigned int option_index = find_opt (data.option_str + 1, lang_mask);
if (early && !(c_option_is_from_cpp_diagnostics (option_index)
- /* For interpret_float. */
- || option_index == OPT_Wc__23_extensions
|| option_index == OPT_Wunknown_pragmas))
return;
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 7d7445b..ec23249 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -497,19 +497,19 @@ C++ ObjC++ Var(warn_cxx11_extensions) Warning Init(1)
Warn about C++11 constructs in code compiled with an older standard.
Wc++14-extensions
-C++ ObjC++ Var(warn_cxx14_extensions) Warning Init(1)
+C++ ObjC++ Var(warn_cxx14_extensions) Warning Init(1) CppReason(CPP_W_CXX14_EXTENSIONS)
Warn about C++14 constructs in code compiled with an older standard.
Wc++17-extensions
-C++ ObjC++ Var(warn_cxx17_extensions) Warning Init(1)
+C++ ObjC++ Var(warn_cxx17_extensions) Warning Init(1) CppReason(CPP_W_CXX17_EXTENSIONS)
Warn about C++17 constructs in code compiled with an older standard.
Wc++20-extensions
-C++ ObjC++ Var(warn_cxx20_extensions) Warning Init(1)
+C++ ObjC++ Var(warn_cxx20_extensions) Warning Init(1) CppReason(CPP_W_CXX20_EXTENSIONS)
Warn about C++20 constructs in code compiled with an older standard.
Wc++23-extensions
-C++ ObjC++ Var(warn_cxx23_extensions) Warning Init(1)
+C++ ObjC++ Var(warn_cxx23_extensions) Warning Init(1) CppReason(CPP_W_CXX23_EXTENSIONS)
Warn about C++23 constructs in code compiled with an older standard.
Wc++26-extensions
diff --git a/gcc/testsuite/c-c++-common/pragma-diag-17.c b/gcc/testsuite/c-c++-common/pragma-diag-17.c
new file mode 100644
index 0000000..a38841b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pragma-diag-17.c
@@ -0,0 +1,25 @@
+/* Test silencing the numeric constant extension pedwarns. */
+/* { dg-options "-pedantic-errors" } */
+/* { dg-additional-options -fext-numeric-literals { target c++14 } } */
+
+#pragma GCC diagnostic push
+
+void f()
+{
+ 2.0j; /* { dg-error "imaginary" } */
+ 1.0dd; /* { dg-error "decimal float" } */
+ 1.0d; /* { dg-error "double constant" } */
+ 0b0100; /* { dg-error "binary constant" "" { target { ! c++14 } } } */
+#pragma GCC diagnostic ignored "-Wpedantic"
+ 2.0j;
+ 1.0dd;
+ 1.0d;
+
+#ifdef __cplusplus
+#pragma GCC diagnostic ignored "-Wc++14-extensions"
+#endif
+ 0b0100;
+
+ 1.0K; /* { dg-bogus {fixed-point types not supported in C\+\+} "" { xfail c++ } } */
+ /* { dg-error {fixed-point types not supported for this target} "" { target { c && { ! fixed_point } } } .-1 } */
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/va-opt1.C b/gcc/testsuite/g++.dg/cpp0x/va-opt1.C
new file mode 100644
index 0000000..e22ad98
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/va-opt1.C
@@ -0,0 +1,18 @@
+/* Test silencing C++20 va_opt pedwarns. */
+
+#pragma GCC diagnostic push
+
+void f()
+{
+#define MAC1(FMT, ...) __builtin_printf ((FMT) __VA_OPT__(,) __VA_ARGS__)
+ /* { dg-error "variadic macro" "" { target { c++98_only } } .-1 } */
+ /* { dg-error "VA_OPT" "" { target { c++17_down } } .-2 } */
+ MAC1("foo"); /* { dg-error "empty macro arguments" "" { target c++98_only } } */
+ /* { dg-error "at least one argument" "" { target c++17_down } .-1 } */
+
+#pragma GCC diagnostic ignored "-Wvariadic-macros"
+#pragma GCC diagnostic ignored "-Wc++20-extensions"
+
+#define MAC2(FMT, ...) __builtin_printf ((FMT) __VA_OPT__(,) __VA_ARGS__)
+ MAC2("foo");
+}
diff --git a/gcc/testsuite/g++.dg/cpp23/named-universal-char-escape3.C b/gcc/testsuite/g++.dg/cpp23/named-universal-char-escape3.C
new file mode 100644
index 0000000..03c58b3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/named-universal-char-escape3.C
@@ -0,0 +1,19 @@
+/* Test silencing C++23 #warning and P2071 escape pedwarns. */
+#pragma GCC diagnostic push
+
+void f() {
+
+#warning foo /* { dg-warning foo } */
+/* { dg-error "extension" "" { target { ! c++23 } } .-1 } */
+
+'\x{0f}'; /* { dg-error "delimited escape" "" { target { ! c++23 } } }*/
+"\N{OHM SIGN}"; /* { dg-error "named universal character" "" { target { ! c++23 } } }*/
+
+#pragma GCC diagnostic ignored "-Wc++23-extensions"
+
+#warning foo /* { dg-warning foo } */
+
+'\x{0f}';
+"\N{OHM SIGN}";
+
+}