C++ PATCH for c++/79519, ICE with deleted template friend

Submitted by Jason Merrill on March 20, 2017, 8:36 p.m.

Details

Message ID CADzB+2=_ZMWzV0oBxaeJ+yYpYRdHSPLw==VU=b+oSrKFOTN3KQ@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill March 20, 2017, 8:36 p.m.
A while back I fixed =delete of namespace-scope friend functions, but
that led to this ICE.  Fixed by recognizing that =delete is also a
definition in the place that checks for inappropriate definitions of
friend functions.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 0ba077c5f36b64b1c1bd1e6fb7ec240b06e9351b
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 20 15:18:42 2017 -0400

            PR c++/79519 - ICE with deleted template friend.
    
            * decl.c (grokdeclarator): Complain about misplaced function
            definition using =, as well.

Patch hide | download patch | download mbox

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 0a92566..516b93c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -11365,9 +11365,9 @@  grokdeclarator (const cp_declarator *declarator,
       else if (TREE_CODE (type) == FUNCTION_TYPE)
 	{
 	  if (current_class_type
-	      && (!friendp || funcdef_flag))
+	      && (!friendp || funcdef_flag || initialized))
 	    {
-	      error (funcdef_flag
+	      error (funcdef_flag || initialized
 		     ? G_("cannot define member function %<%T::%s%> "
 			  "within %<%T%>")
 		     : G_("cannot declare member function %<%T::%s%> "
diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted13.C b/gcc/testsuite/g++.dg/cpp0x/deleted13.C
new file mode 100644
index 0000000..f10551f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/deleted13.C
@@ -0,0 +1,12 @@ 
+// PR c++/79519
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  template<typename> void foo();
+};
+
+struct B
+{
+  template<typename> friend void A::foo() = delete; // { dg-error "" }
+};