From c7b0e0273ea01ccc3a8b8065944f89b6d619e787 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Tue, 17 Oct 2006 22:35:29 +0000 Subject: [PATCH] re PR c++/29039 (implicitly defined constructor for class with reference member) 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. PR c++/29039 * g++.dg/init/ctor8.C: New test. From-SVN: r117834 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/method.c | 2 +- gcc/cp/typeck2.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/init/ctor8.C | 11 +++++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/ctor8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 47285866dc6..b759ba42580 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2006-10-17 Mark Mitchell + + 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 PR c++/27270 diff --git a/gcc/cp/method.c b/gcc/cp/method.c index e2106fff55c..ded0af04716 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -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); } diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 725c85fa597..12987cfab1e 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1333,9 +1333,9 @@ build_functional_cast (tree exp, tree parms) 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4fed928d1ca..57ec350bd85 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-10-17 Mark Mitchell + + PR c++/29039 + * g++.dg/init/ctor8.C: New test. + 2006-10-17 Mark Mitchell PR c++/27270 diff --git a/gcc/testsuite/g++.dg/init/ctor8.C b/gcc/testsuite/g++.dg/init/ctor8.C new file mode 100644 index 00000000000..9723892f91c --- /dev/null +++ b/gcc/testsuite/g++.dg/init/ctor8.C @@ -0,0 +1,11 @@ +// PR c++/29039 + +typedef struct S { // { dg-error "reference" } + int &r; +}; + +S f () { + return S (); // { dg-error "synthesized" } +} + +