re PR c++/21347 (spurious warning with -Wctor-dtor-privacy)
authorMark Mitchell <mark@codesourcery.com>
Sat, 15 Oct 2005 18:13:25 +0000 (18:13 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sat, 15 Oct 2005 18:13:25 +0000 (18:13 +0000)
PR c++/21347
* class.c (maybe_warn_about_overly_private_class): Lazy
constructors are public.
PR c++/21347
* g++.dg/warn/Wctor-dtor.C: New test.

From-SVN: r105441

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wctor-dtor.C [new file with mode: 0644]

index 7b2ff855d6460dbd85903660364387e4d3ca3c26..51089eb9f90116a0dd7f1882f1f23fe442d93f68 100644 (file)
@@ -1,3 +1,9 @@
+2005-10-15  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/21347
+       * class.c (maybe_warn_about_overly_private_class): Lazy
+       constructors are public.
+
 2005-10-14  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/19565
index dc52975204b208f7e38da8aa298fbd7569830139..b8254fe4a09ab84ef6a2a38bf89b59dd0b75397c 100644 (file)
@@ -1537,7 +1537,10 @@ maybe_warn_about_overly_private_class (tree t)
       return;
     }
 
-  if (TYPE_HAS_CONSTRUCTOR (t))
+  if (TYPE_HAS_CONSTRUCTOR (t)
+      /* Implicitly generated constructors are always public.  */
+      && (!CLASSTYPE_LAZY_DEFAULT_CTOR (t)
+         || !CLASSTYPE_LAZY_COPY_CTOR (t)))
     {
       int nonprivate_ctor = 0;
 
index 04465c5c90221d65a656a40318dbec9f7200fd01..70f1a0b27a500c90d040fa43f027a8e328a9b8df 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-15  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/21347
+       * g++.dg/warn/Wctor-dtor.C: New test.
+
 2005-10-14  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c/23439
diff --git a/gcc/testsuite/g++.dg/warn/Wctor-dtor.C b/gcc/testsuite/g++.dg/warn/Wctor-dtor.C
new file mode 100644 (file)
index 0000000..15efb6b
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/21347
+// { dg-options "-Wctor-dtor-privacy" }
+
+class A {
+public:
+  int x;
+  int getX() { return x; } // comment out to avoid warning
+};
+
+int foo() {
+  A a; // accepted: clearly the ctor is not private
+  return a.x;
+}