diff mbox

C++ PATCH for c++/46736 (missing diagnostic for invalid =default)

Message ID 4D014B92.50606@redhat.com
State New
Headers show

Commit Message

Jason Merrill Dec. 9, 2010, 9:35 p.m. UTC
On 12/09/2010 08:42 AM, Dodji Seketeli wrote:
> Not very important but it looks like this patch does not correspond to
> the subject.

Oops, here's the real patch.
commit 21f80a31bf2440b3b8a62f20fa6298be6cb769b6
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Dec 8 20:00:27 2010 +0000

    	PR c++/46736
    	* decl.c (cp_finish_decl): Complain about an implicitly deleted
    	method defaulted outside the class.
    	* method.c (maybe_explain_implicit_delete): Don't check DECL_INITIAL.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167601 138bc75d-0d04-0410-961f-82ee72b054a4
diff mbox

Patch

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5b4dfb7..b72b588 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6094,7 +6094,9 @@  cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 		{
 		  /* An out-of-class default definition is defined at
 		     the point where it is explicitly defaulted.  */
-		  if (DECL_INITIAL (decl) == error_mark_node)
+		  if (DECL_DELETED_FN (decl))
+		    maybe_explain_implicit_delete (decl);
+		  else if (DECL_INITIAL (decl) == error_mark_node)
 		    synthesize_method (decl);
 		}
 	      else
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index ed75a64..dc72355 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1318,8 +1318,7 @@  maybe_explain_implicit_delete (tree decl)
   /* If decl is a clone, get the primary variant.  */
   decl = DECL_ORIGIN (decl);
   gcc_assert (DECL_DELETED_FN (decl));
-  if (DECL_DEFAULTED_FN (decl)
-      && DECL_INITIAL (decl) == NULL_TREE)
+  if (DECL_DEFAULTED_FN (decl))
     {
       /* Not marked GTY; it doesn't need to be GC'd or written to PCH.  */
       static htab_t explained_htab;
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted21.C b/gcc/testsuite/g++.dg/cpp0x/defaulted21.C
new file mode 100644
index 0000000..3e74033
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted21.C
@@ -0,0 +1,20 @@ 
+// PR c++/46736
+// { dg-options -std=c++0x }
+
+struct U {
+  U();
+  U(U const&);
+};
+
+struct X {
+  U const u;
+  X();
+  X(X&&);
+};
+
+X::X(X&&)=default;		// { dg-error "implicitly deleted" }
+// { dg-error "does not have a move constructor" "" { target *-*-* } 15 }
+
+X f() {
+  return X();
+}