The following ill-formed code is accepted: typedef struct { int &r; } S; S f () { return S (); } 12.1 ; 5 states that if there is no user-declared constructor for a class, a default constructor is implicitly declared. 12.1 ; 7 states that such a constructor is implicitly defined when it is used to create an object of its class type, and that it performs the same set of initializations that would be performed by a user-written default constructor with an empty mem-initializer-list. 12.6.2 ; 4 says that if an entity not named in a mem-initializer-id is of reference type, the program is ill-formed.
Even though we give a weird error message in 3.4.0 and before, we rejected the code: t.cc: In function `struct S f()': t.cc:11: no matching function for call to `S::._0 ()' t.cc:6: candidates are: S::._0(const S &) Confirmed, a regression.
Subject: Bug 29039 Author: mmitchel Date: Tue Oct 17 22:35:29 2006 New Revision: 117834 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117834 Log: 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. Added: trunk/gcc/testsuite/g++.dg/init/ctor8.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/method.c trunk/gcc/cp/typeck2.c trunk/gcc/testsuite/ChangeLog
Fixed in 4.2.0.
Won't fix in GCC-4.0.x. Adjusting milestone.
Subject: Bug 29039 Author: jason Date: Tue Feb 12 06:37:34 2008 New Revision: 132254 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132254 Log: PR c++/34094 * decl2.c (cp_write_global_declarations): Don't write out static data members with DECL_IN_AGGR_P set. PR c++/33916 * Revert: 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. Removed: branches/gcc-4_2-branch/gcc/testsuite/g++.dg/init/ctor8.C Modified: branches/gcc-4_2-branch/gcc/cp/ChangeLog branches/gcc-4_2-branch/gcc/cp/decl2.c branches/gcc-4_2-branch/gcc/cp/typeck2.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
I reverted Mark's patch for 4.2.4 because it caused PR 33916. This bug is fixed in 4.3.0 by the patch for 33916, which seems too complex to risk backporting.
Closing 4.1 branch.
Closing 4.2 branch, fixed in 4.3.