From 9f119e29269b9a63f36c014b1429e96c133148b4 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 14 Jun 2019 14:49:57 +0000 Subject: [PATCH] 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. From-SVN: r272291 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/class.c | 8 ++++---- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C | 5 +++++ gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h | 7 +++++++ 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C create mode 100644 gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 62e541736ec..ad353142a2f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-06-14 Marek Polacek + + PR c++/90884 - stray note with -Wctor-dtor-privacy. + * class.c (maybe_warn_about_overly_private_class): Guard the call to + inform. + 2019-06-12 Jason Merrill PR c++/85552 - wrong instantiation of dtor for DMI. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 4fdb0f328cc..de37e43d04c 100644 --- a/gcc/cp/class.c +++ b/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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3cebc569748..c7604d6dc4d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-06-14 Marek Polacek + + PR c++/90884 - stray note with -Wctor-dtor-privacy. + * g++.dg/warn/ctor-dtor-privacy-4.C: New. + * g++.dg/warn/ctor-dtor-privacy-4.h: New. + 2019-06-14 Richard Biener * gcc.dg/tree-ssa/ldist-26.c: Adjust. diff --git a/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C b/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C new file mode 100644 index 00000000000..fcad34e000c --- /dev/null +++ b/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 a/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h b/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h new file mode 100644 index 00000000000..d67fd26943e --- /dev/null +++ b/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 -- 2.30.2