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]

PATCH: PR c++/32245


This patch fixes PR c++/32245, a GCC 4.2.x P1.

Here, we were building a POD containing a pointer-to-member via a
functional cast.  That implies a zero-initialization, but we were
forgetting that the zero-initialization of a pointer-to-member is to
give it the bit-pattern -1.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.  I will
backport to 4.2.
 
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2007-07-05  Mark Mitchell  <mark@codesourcery.com>

	PR c++/32245
	* init.c (build_zero_init): Always build an initializer for
	non-static storage.
	* typeck2.c (build_functional_cast): Use build_zero_init.

2007-07-05  Mark Mitchell  <mark@codesourcery.com>

	PR c++/32245
	* g++.dg/init/ptrmem4.C: New test.

Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(revision 126293)
+++ gcc/cp/init.c	(working copy)
@@ -196,7 +196,7 @@ build_zero_init (tree type, tree nelts, 
 	     corresponding to base classes as well.  Thus, iterating
 	     over TYPE_FIELDs will result in correct initialization of
 	     all of the subobjects.  */
-	  if (static_storage_p && !zero_init_p (TREE_TYPE (field)))
+	  if (!static_storage_p || !zero_init_p (TREE_TYPE (field)))
 	    {
 	      tree value = build_zero_init (TREE_TYPE (field),
 					    /*nelts=*/NULL_TREE,
Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c	(revision 126287)
+++ gcc/cp/typeck2.c	(working copy)
@@ -1340,7 +1340,9 @@ build_functional_cast (tree exp, tree pa
       && !CLASSTYPE_NON_POD_P (type)
       && TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
     {
-      exp = build_constructor (type, NULL);
+      exp = build_zero_init (type, 
+			     /*nelts=*/NULL_TREE,
+			     /*static_storage_p=*/false);
       return get_target_expr (exp);
     }
 
Index: gcc/testsuite/g++.dg/init/ptrmem4.C
===================================================================
--- gcc/testsuite/g++.dg/init/ptrmem4.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/ptrmem4.C	(revision 0)
@@ -0,0 +1,13 @@
+// PR c++/32245
+// { dg-do run } 
+
+struct foo {
+  int mem1;
+  int foo::* mem2;
+};
+
+int main () {
+  foo x = { 0 } ;
+  if (x.mem2 != foo().mem2)
+    return 1;
+}


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