PR c++/90884 - stray note with -Wctor-dtor-privacy.
authorMarek Polacek <polacek@redhat.com>
Fri, 14 Jun 2019 14:49:57 +0000 (14:49 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 14 Jun 2019 14:49:57 +0000 (14:49 +0000)
* 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
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-4.h [new file with mode: 0644]

index 62e541736ecf053a033b15f1eaca6db207872ce3..ad353142a2fc2fb5f354f7be678a2aa00d0d6e31 100644 (file)
@@ -1,3 +1,9 @@
+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-06-12  Jason Merrill  <jason@redhat.com>
 
        PR c++/85552 - wrong instantiation of dtor for DMI.
index 4fdb0f328cc0e22a5f2140fe76b06bf507e42bc0..de37e43d04c1960191a377a58edc7ac338070b29 100644 (file)
@@ -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);
index 3cebc56974875b148fb65098b83d61fc517e00be..c7604d6dc4ddafe149c4768633870c09c2960d78 100644 (file)
@@ -1,3 +1,9 @@
+2019-06-14  Marek Polacek  <polacek@redhat.com>
+
+       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  <rguenther@suse.de>
 
        * 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 (file)
index 0000000..fcad34e
--- /dev/null
@@ -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 (file)
index 0000000..d67fd26
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma GCC system_header
+
+namespace std {
+struct __nonesuch {
+  __nonesuch(__nonesuch const &);
+};
+} // namespace std