Bug 29039 - [4.2 Regression] implicitly defined constructor for class with reference member
Summary: [4.2 Regression] implicitly defined constructor for class with reference member
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P2 normal
Target Milestone: 4.3.0
Assignee: Mark Mitchell
URL:
Keywords: accepts-invalid, monitored
Depends on:
Blocks: 29843
  Show dependency treegraph
 
Reported: 2006-09-12 18:52 UTC by Jorn Wolfgang Rennecke
Modified: 2009-03-30 17:05 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3 3.0.4 3.2.3 2.95.3 3.4.0 3.4.6 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0
Known to fail: 4.0.0 4.0.4 4.1.0 4.1.3 4.2.4 4.2.5
Last reconfirmed: 2006-09-12 19:08:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jorn Wolfgang Rennecke 2006-09-12 18:52:31 UTC
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.
Comment 1 Andrew Pinski 2006-09-12 19:08:28 UTC
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.
Comment 2 Mark Mitchell 2006-10-17 22:35:37 UTC
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

Comment 3 Mark Mitchell 2006-10-17 22:52:27 UTC
Fixed in 4.2.0.
Comment 4 Gabriel Dos Reis 2007-02-03 20:04:40 UTC
Won't fix in GCC-4.0.x.  Adjusting milestone.
Comment 5 Jason Merrill 2008-02-12 06:38:23 UTC
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

Comment 6 Jason Merrill 2008-02-12 06:39:59 UTC
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.
Comment 7 Joseph S. Myers 2008-07-04 21:30:34 UTC
Closing 4.1 branch.
Comment 8 Joseph S. Myers 2009-03-30 17:05:30 UTC
Closing 4.2 branch, fixed in 4.3.