[gcc/devel/omp/gcc-9] PR c++/90884 - stray note with -Wctor-dtor-privacy.

Tobias Burnus burnus@gcc.gnu.org
Thu Mar 5 13:54:00 GMT 2020


https://gcc.gnu.org/g:3bc5b51175fa77f115bd61a83602b6b76977cf18

commit 3bc5b51175fa77f115bd61a83602b6b76977cf18
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Aug 15 18:35:07 2019 +0000

    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:
---
 gcc/cp/ChangeLog                                | 6 ++++++
 gcc/cp/class.c                                  | 8 ++++----
 gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C | 5 +++++
 gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h | 7 +++++++
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6e9cb98..f40ccc0 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  <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.
+
 2019-08-14  Martin Sebor  <msebor@redhat.com>
 
 	Backported from mainline
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index a47777c..b3b06ec 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 0000000..fcad34e
--- /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 0000000..d67fd26
--- /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



More information about the Gcc-cvs mailing list