public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Lewis Hyatt <lhyatt@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-4748] c++: Make -Wunknown-pragmas controllable by #pragma GCC diagnostic [PR89038]
Date: Thu, 19 Oct 2023 13:11:29 +0000 (GMT)	[thread overview]
Message-ID: <20231019131129.3A1E73858428@sourceware.org> (raw)

https://gcc.gnu.org/g:19cc4b9d74940f29c961e2a5a8b1fa84992d3d30

commit r14-4748-g19cc4b9d74940f29c961e2a5a8b1fa84992d3d30
Author: Lewis Hyatt <lhyatt@gmail.com>
Date:   Wed Oct 18 12:37:08 2023 -0400

    c++: Make -Wunknown-pragmas controllable by #pragma GCC diagnostic [PR89038]
    
    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.

Diff:
---
 gcc/c-family/c-pragma.cc                            |  3 ++-
 gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 293311dd4ce9..98dfb0f108b7 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -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
index 000000000000..fb58739e2bce
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c
@@ -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" } */

                 reply	other threads:[~2023-10-19 13:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231019131129.3A1E73858428@sourceware.org \
    --to=lhyatt@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).