diff mbox series

[PR,c++/84694] ICE on template friend decl

Message ID fc41cec4-9fe1-dc10-ef31-eccd4722bed9@acm.org
State New
Headers show
Series [PR,c++/84694] ICE on template friend decl | expand

Commit Message

Nathan Sidwell March 5, 2018, 4:10 p.m. UTC
This fixes an ICE with a friend decl.  Although the reported source is 
invalid, we can turn it into valid, but useless, source.  ISTM that we 
should be generating a raw identifier_node here, but finding the 
TEMPLATE_DECL at parse time.  But that's a change for another day.  This 
restores the previous non-crashing behaviour.

nathan
diff mbox series

Patch

2018-03-05  Nathan Sidwell  <nathan@acm.org>

	PR c++/84694
	* friend.c (do_friend): Restore check for identifier_p inside
	TEMPLATE_ID_EXPR.

	PR c++/84694
	* g++.dg/template/pr84694.C: New.

Index: cp/friend.c
===================================================================
--- cp/friend.c	(revision 258244)
+++ cp/friend.c	(working copy)
@@ -495,7 +495,8 @@  do_friend (tree ctype, tree declarator,
   if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR)
     {
       declarator = TREE_OPERAND (declarator, 0);
-      declarator = OVL_NAME (declarator);
+      if (!identifier_p (declarator))
+	declarator = OVL_NAME (declarator);
     }
 
   if (ctype)
Index: testsuite/g++.dg/template/pr84694.C
===================================================================
--- testsuite/g++.dg/template/pr84694.C	(revision 0)
+++ testsuite/g++.dg/template/pr84694.C	(working copy)
@@ -0,0 +1,6 @@ 
+// PR c++84694 ICE on friend decl
+template<typename>
+struct a {
+  template<int ()> void b();
+  friend void b<0>(); // ICEd with useless friend decl
+};