This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 29039


This patch fixes PR c++/29039, an accepts-invalid regression.  As
stated in the PR, we were trying to avoid creating a default
constructor for non-PODs that had no constructible data members (a
rare case), but that fails to detect the case of an invald implicit
constructor for a class with a data member of reference type.  (Such a
class must be initialized explicitly with a brace-enclosed
initializer.)

Tested on x86_64-unknown-linux-gnu, applied on the mainline.  I will
apply to the 4.1 branch when testing completes.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-10-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29039
	* typeck2.c (build_functional_cast): Don't zero-initialize
	non-PODs; instead, call their constructors.
	* method.c (synthesize_method): Always build mem-initializers, if
	we're synthesizing the default constructor.

2006-10-17  Mark Mitchell  <mark@codesourcery.com>

	PR c++/29039
	* g++.dg/init/ctor8.C: New test.
	
Index: gcc/cp/method.c
===================================================================
--- gcc/cp/method.c	(revision 117789)
+++ gcc/cp/method.c	(working copy)
@@ -784,7 +784,7 @@ synthesize_method (tree fndecl)
       tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
       if (arg_chain != void_list_node)
 	do_build_copy_constructor (fndecl);
-      else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
+      else
 	finish_mem_initializers (NULL_TREE);
     }
 
Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c	(revision 117814)
+++ gcc/cp/typeck2.c	(working copy)
@@ -1333,9 +1333,9 @@ build_functional_cast (tree exp, tree pa
   if (parms && TREE_CHAIN (parms) == NULL_TREE)
     return build_c_cast (type, TREE_VALUE (parms));
 
-  /* We need to zero-initialize POD types.  Let's do that for everything
-     that doesn't need a constructor.  */
-  if (parms == NULL_TREE && !TYPE_NEEDS_CONSTRUCTING (type)
+  /* We need to zero-initialize POD types.  */
+  if (parms == NULL_TREE 
+      && !CLASSTYPE_NON_POD_P (type)
       && TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
     {
       exp = build_constructor (type, NULL);

Index: gcc/testsuite/g++.dg/init/ctor8.C
===================================================================
--- gcc/testsuite/g++.dg/init/ctor8.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/ctor8.C	(revision 0)
@@ -0,0 +1,11 @@
+// PR c++/29039
+
+typedef struct S { // { dg-error "reference" }
+  int &r; 
+};
+
+S f () {
+  return S (); // { dg-error "synthesized" }
+}
+
+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]