public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH to handling of exception specs in system headers
Date: Wed, 27 May 2015 20:59:00 -0000	[thread overview]
Message-ID: <55662E61.4020707@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 330 bytes --]

-pedantic shouldn't change something from OK into an error, but it was 
doing so for redeclaration of a declaration from a system header with a 
mismatched exception specification.  And whether we are strict about 
things in system headers should be controlled by -Wsystem-headers.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: ped-sys.patch --]
[-- Type: text/x-patch, Size: 2085 bytes --]

commit 8c029a40a7d4348c432f09eb2512a485cfe9bda8
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 26 11:47:27 2015 -0400

    	* decl.c (check_redeclaration_exception_specification): Depend on
    	-Wsystem-headers rather than -pedantic.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 420c7f40..a8cb358 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -1213,14 +1213,19 @@ check_redeclaration_exception_specification (tree new_decl,
      all declarations, including the definition and an explicit
      specialization, of that function shall have an
      exception-specification with the same set of type-ids.  */
-  if ((pedantic || ! DECL_IN_SYSTEM_HEADER (old_decl))
-      && ! DECL_IS_BUILTIN (old_decl)
+  if (! DECL_IS_BUILTIN (old_decl)
       && flag_exceptions
       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
     {
-      error ("declaration of %q+F has a different exception specifier",
-	     new_decl);
-      inform (0, "from previous declaration %q+F", old_decl);
+      const char *msg
+	= "declaration of %q+F has a different exception specifier";
+      bool complained = true;
+      if (! DECL_IN_SYSTEM_HEADER (old_decl))
+	error (msg, new_decl);
+      else
+	complained = pedwarn (0, OPT_Wsystem_headers, msg, new_decl);
+      if (complained)
+	inform (0, "from previous declaration %q+F", old_decl);
     }
 }
 
diff --git a/gcc/testsuite/g++.dg/warn/Wsystem-headers1.C b/gcc/testsuite/g++.dg/warn/Wsystem-headers1.C
new file mode 100644
index 0000000..ac5c30d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wsystem-headers1.C
@@ -0,0 +1,3 @@
+#include <stdlib.h>
+
+extern double atof (const char *);
diff --git a/gcc/testsuite/g++.dg/warn/Wsystem-headers1a.C b/gcc/testsuite/g++.dg/warn/Wsystem-headers1a.C
new file mode 100644
index 0000000..68f6ea1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wsystem-headers1a.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target *-*-*gnu } }
+// { dg-options "-Wsystem-headers" }
+
+#include <stdlib.h>
+
+extern double atof (const char *); // { dg-warning "different exception spec" }

             reply	other threads:[~2015-05-27 20:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 20:59 Jason Merrill [this message]
2015-06-01 12:13 ` Rainer Orth
2015-06-01 14:58   ` Jason Merrill
2015-06-01 15:34     ` Rainer Orth
2015-06-01 17:05       ` Jason Merrill
2015-06-02 14:19         ` Rainer Orth

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=55662E61.4020707@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@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).