Patchwork [C++] PR 53096

login
register
mail settings
Submitter Paolo Carlini
Date April 25, 2012, 2:25 p.m.
Message ID <4F980955.5010200@oracle.com>
Download mbox | patch
Permalink /patch/154955/
State New
Headers show

Comments

Paolo Carlini - April 25, 2012, 2:25 p.m.
Hi,

this PR is about the resolution of core/1333 being unimplemented, thus 
we reject things like:

     struct foo
     {
       foo(foo&) = default; // ERROR HERE
     };

(and this can be annoying, as explained by Eric on the reflector, for 
example when one has to resort to out-of-class defaulting which means 
non-trivial)

Thus, the below elementary patch appears to work fine (I also double 
checked that in such cases the type remains trivial). It's all there is 
to it?

Thanks,
Paolo.

/////////////////////
/cp
2012-04-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53096
	* class.c (check_bases_and_members): Implement core/1333, do not
	disallow defaulted in the class body special members.

/testsuite
2012-04-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53096
	* g++.dg/cpp0x/defaulted35.C: New.
	* g++.dg/cpp0x/defaulted15.C: Adjust.
Jason Merrill - April 26, 2012, 2:15 p.m.
On 04/25/2012 10:25 AM, Paolo Carlini wrote:
> Thus, the below elementary patch appears to work fine (I also double
> checked that in such cases the type remains trivial). It's all there is
> to it?

Unfortunately, I don't think so; there's a lot of code in the compiler 
that assumes that trivial constructors are also always callable. 
However, that might not be as big an issue for the copy constructor as 
it is for the default constructor, since copies go through overload 
resolution.  So I guess if this patch passes the testsuite it's OK.

Jason
Paolo Carlini - April 26, 2012, 10:02 p.m.
On 04/26/2012 04:15 PM, Jason Merrill wrote:
> On 04/25/2012 10:25 AM, Paolo Carlini wrote:
>> Thus, the below elementary patch appears to work fine (I also double
>> checked that in such cases the type remains trivial). It's all there is
>> to it?
> Unfortunately, I don't think so; there's a lot of code in the compiler 
> that assumes that trivial constructors are also always callable. 
> However, that might not be as big an issue for the copy constructor as 
> it is for the default constructor, since copies go through overload 
> resolution.  So I guess if this patch passes the testsuite it's OK.
Ok, thanks for the clarification. Patch indeed passes testing on 
x86_&4-linux, I'm going to reboot & retest & commit if everything goes 
well. Let's see if people interested in this kind of defaulted special 
members can come up with more complex testcases which we are still 
mishandling...

Thanks again!
Paolo.

Patch

Index: testsuite/g++.dg/cpp0x/defaulted15.C
===================================================================
--- testsuite/g++.dg/cpp0x/defaulted15.C	(revision 186816)
+++ testsuite/g++.dg/cpp0x/defaulted15.C	(working copy)
@@ -43,7 +43,7 @@  SA(__has_trivial_copy(E));
 
 struct F
 {
-  F(F&) = default;		// { dg-error "non-const" }
+  F(F&) = default;
 };
 
 struct G: public F
Index: testsuite/g++.dg/cpp0x/defaulted35.C
===================================================================
--- testsuite/g++.dg/cpp0x/defaulted35.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/defaulted35.C	(revision 0)
@@ -0,0 +1,8 @@ 
+// PR c++/53096
+// { dg-options -std=c++0x }
+
+struct foo
+{
+  foo(foo&) = default;
+  foo& operator=(foo&) = default;
+};
Index: cp/class.c
===================================================================
--- cp/class.c	(revision 186816)
+++ cp/class.c	(working copy)
@@ -1,6 +1,7 @@ 
 /* Functions related to building classes and their related objects.
    Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011,
+   2012
    Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
@@ -5144,9 +5145,6 @@  check_bases_and_members (tree t)
 		 give the synthesis error.  */
 	      error ("%q+D declared to take const reference, but implicit "
 		     "declaration would take non-const", fn);
-	    else if (imp_const_p && !fn_const_p)
-	      error ("%q+D declared to take non-const reference cannot be "
-		     "defaulted in the class body", fn);
 	  }
 	defaulted_late_check (fn);
       }