C++ PATCH: PR 21347

Mark Mitchell mark@codesourcery.com
Sat Oct 15 18:12:00 GMT 2005


This patch fixes a warning regression.  When I made the C++ front-end
declare implicit constructors only as needed, I failed to update the
warning logic to recognize that lazily-generated constructors are in
fact constructors just the same.  (Destructors don't have the same
issue, in case you're wondering, because the check for them is done
differently due to the fact that there can only be one destructor for
a class.)

Tested on x86_64-unknown-linux-gnu, applied on the mainline and on the
4.0 branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

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-15  Mark Mitchell  <mark@codesourcery.com>

	PR c++/21347
	* g++.dg/warn/Wctor-dtor.C: New test.

Index: gcc/cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.735
diff -c -5 -p -r1.735 class.c
*** gcc/cp/class.c	12 Oct 2005 20:54:49 -0000	1.735
--- gcc/cp/class.c	15 Oct 2005 02:25:14 -0000
*************** maybe_warn_about_overly_private_class (t
*** 1537,1547 ****
        warning (0, "%q#T only defines a private destructor and has no friends",
  	       t);
        return;
      }
  
!   if (TYPE_HAS_CONSTRUCTOR (t))
      {
        int nonprivate_ctor = 0;
  
        /* If a non-template class does not define a copy
  	 constructor, one is defined for it, enabling it to avoid
--- 1537,1550 ----
        warning (0, "%q#T only defines a private destructor and has no friends",
  	       t);
        return;
      }
  
!   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;
  
        /* If a non-template class does not define a copy
  	 constructor, one is defined for it, enabling it to avoid
Index: gcc/testsuite/g++.dg/warn/Wctor-dtor.C
===================================================================
RCS file: gcc/testsuite/g++.dg/warn/Wctor-dtor.C
diff -N gcc/testsuite/g++.dg/warn/Wctor-dtor.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/g++.dg/warn/Wctor-dtor.C	15 Oct 2005 02:25:27 -0000
***************
*** 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;
+ }



More information about the Gcc-patches mailing list