From 550d1bf420954b9e7dbf2695b6fd42b329d91604 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Sat, 15 Oct 2005 18:13:25 +0000 Subject: [PATCH] re PR c++/21347 (spurious warning with -Wctor-dtor-privacy) 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 | 6 ++++++ gcc/cp/class.c | 5 ++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Wctor-dtor.C | 13 +++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wctor-dtor.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7b2ff855d64..51089eb9f90 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2005-10-15 Mark Mitchell + + PR c++/21347 + * class.c (maybe_warn_about_overly_private_class): Lazy + constructors are public. + 2005-10-14 Mark Mitchell PR c++/19565 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index dc52975204b..b8254fe4a09 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 04465c5c902..70f1a0b27a5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-10-15 Mark Mitchell + + PR c++/21347 + * g++.dg/warn/Wctor-dtor.C: New test. + 2005-10-14 Volker Reichelt 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 index 00000000000..15efb6b578d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wctor-dtor.C @@ -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; +}