From: Marek Polacek Date: Thu, 15 Aug 2019 18:35:07 +0000 (+0000) Subject: PR c++/90884 - stray note with -Wctor-dtor-privacy. X-Git-Tag: releases/gcc-9.3.0~721 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bc5b51175fa77f115bd61a83602b6b76977cf18;p=thirdparty%2Fgcc.git PR c++/90884 - stray note with -Wctor-dtor-privacy. * class.c (maybe_warn_about_overly_private_class): Guard the call to inform. From-SVN: r274547 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6e9cb982478e..f40ccc07f0bf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -20,6 +20,12 @@ * decl.c (check_default_argument): Don't return nullptr when the arg has side-effects. + 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-08-14 Martin Sebor Backported from mainline diff --git a/gcc/cp/class.c b/gcc/cp/class.c index a47777cdd9ef..b3b06eca3747 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2149,10 +2149,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/g++.dg/warn/ctor-dtor-privacy-4.C b/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C new file mode 100644 index 000000000000..fcad34e000c3 --- /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 000000000000..d67fd26943e7 --- /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