From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: C++ PATCH for c++/90884 - stray note with -Wctor-dtor-privacy
Date: Fri, 14 Jun 2019 12:10:00 -0000 [thread overview]
Message-ID: <20190614121033.GF5989@redhat.com> (raw)
This patch fixes a naked inform call, resulting in bogus note in the
following testcase, if not compiled with -Wsystem-headers.
Bootstrap/regtest running on x86_64-linux, ok for trunk?
2019-06-14 Marek Polacek <polacek@redhat.com>
PR c++/90884 - stray note with -Wctor-dtor-privacy.
* class.c (maybe_warn_about_overly_private_class): Guard the call to
inform.
* g++.dg/warn/ctor-dtor-privacy-4.C: New.
* g++.dg/warn/ctor-dtor-privacy-4.h: New.
diff --git gcc/cp/class.c gcc/cp/class.c
index 4fdb0f328cc..de37e43d04c 100644
--- gcc/cp/class.c
+++ gcc/cp/class.c
@@ -2150,10 +2150,10 @@ maybe_warn_about_overly_private_class (tree t)
if (!nonprivate_ctor)
{
- warning (OPT_Wctor_dtor_privacy,
- "%q#T only defines private constructors and has no friends",
- t);
- if (copy_or_move)
+ bool w = warning (OPT_Wctor_dtor_privacy,
+ "%q#T only defines private constructors and has "
+ "no friends", t);
+ if (w && copy_or_move)
inform (DECL_SOURCE_LOCATION (copy_or_move),
"%q#D is public, but requires an existing %q#T object",
copy_or_move, t);
diff --git gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C
new file mode 100644
index 00000000000..fcad34e000c
--- /dev/null
+++ gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C
@@ -0,0 +1,5 @@
+// PR c++/90884
+// { dg-options "-Wctor-dtor-privacy" }
+// { dg-prune-output "In file included from" }
+
+#include "ctor-dtor-privacy-4.h" // { dg-bogus "is public" }
diff --git gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h
new file mode 100644
index 00000000000..d67fd26943e
--- /dev/null
+++ gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h
@@ -0,0 +1,7 @@
+#pragma GCC system_header
+
+namespace std {
+struct __nonesuch {
+ __nonesuch(__nonesuch const &);
+};
+} // namespace std
next reply other threads:[~2019-06-14 12:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-14 12:10 Marek Polacek [this message]
2019-06-14 14:43 ` Jason Merrill
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=20190614121033.GF5989@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/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).