]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Make -Wunknown-pragmas controllable by #pragma GCC diagnostic [PR89038]
authorLewis Hyatt <lhyatt@gmail.com>
Wed, 18 Oct 2023 16:37:08 +0000 (12:37 -0400)
committerLewis Hyatt <lhyatt@gmail.com>
Thu, 19 Oct 2023 13:09:39 +0000 (09:09 -0400)
As noted on the PR, commit r13-1544, the fix for PR53431, did not handle
the specific case of -Wunknown-pragmas, because that warning is issued
during preprocessing, but not by libcpp directly (it comes from the
cb_def_pragma callback).  Address that by handling this pragma in
addition to libcpp pragmas during the early pragma handler.

gcc/c-family/ChangeLog:

PR c++/89038
* c-pragma.cc (handle_pragma_diagnostic_impl):  Handle
-Wunknown-pragmas during early processing.

gcc/testsuite/ChangeLog:

PR c++/89038
* c-c++-common/cpp/Wunknown-pragmas-1.c: New test.

gcc/c-family/c-pragma.cc
gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c [new file with mode: 0644]

index 293311dd4ce9fa58b9de486a257b09a26b0b98de..98dfb0f108b7ccf45a8c33ae7234546bc82e7620 100644 (file)
@@ -963,7 +963,8 @@ handle_pragma_diagnostic_impl ()
   /* option_string + 1 to skip the initial '-' */
   unsigned int option_index = find_opt (data.option_str + 1, lang_mask);
 
-  if (early && !c_option_is_from_cpp_diagnostics (option_index))
+  if (early && !(c_option_is_from_cpp_diagnostics (option_index)
+                || option_index == OPT_Wunknown_pragmas))
     return;
 
   if (option_index == OPT_SPECIAL_unknown)
diff --git a/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c b/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c
new file mode 100644 (file)
index 0000000..fb58739
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c++/89038 */
+/* { dg-additional-options "-Wunknown-pragmas" } */
+
+#pragma oops /* { dg-warning "-:-Wunknown-pragmas" } */
+#pragma GGC diagnostic push /* { dg-warning "-:-Wunknown-pragmas" } */
+#pragma GCC diagnostics push /* { dg-warning "-:-Wunknown-pragmas" } */
+
+/* Test we can disable the warnings.  */
+#pragma GCC diagnostic ignored "-Wunknown-pragmas"
+
+#pragma oops /* { dg-bogus "-:-Wunknown-pragmas" } */
+#pragma GGC diagnostic push /* { dg-bogus "-:-Wunknown-pragmas" } */
+#pragma GCC diagnostics push /* { dg-bogus "-:-Wunknown-pragmas" } */