This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: PR c++/32245
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 5 Jul 2007 18:35:52 -0700
- Subject: PATCH: PR c++/32245
- Reply-to: mark at codesourcery dot com
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;
+}