diff mbox

[C++/80979] ADL of friends

Message ID 52683ee8-226b-629a-c882-5a47f8250227@acm.org
State New
Headers show

Commit Message

Nathan Sidwell June 6, 2017, 3:10 p.m. UTC
This fixes 80979, and ICE in the new duplicate lookup matching code. 
That code is enabled when we discover using declarations are in play. 
And it was barfing on meeting an already-marked function.

That function was in the lookup twice, which was a surprise.

That had happened because the function was a friend, but not an 
invisible one.  So we added it as part of the namespace ADL and also as 
when adding the class's friends.  We only later discovered functions 
introduced by using declaration.

The fix is to only add invisible friends during the class ADL.

nathan
diff mbox

Patch

2017-06-06  Nathan Sidwell  <nathan@acm.org>

	PR c++/80979
	* name-lookup.c (adl_class_only): Don't add visible friends.

Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 248914)
+++ cp/name-lookup.c	(working copy)
@@ -801,6 +801,12 @@  name_lookup::adl_class_only (tree type)
 	  if (CP_DECL_CONTEXT (fn) != context)
 	    continue;
 
+	  /* Only interested in anticipated friends.  (Non-anticipated
+	     ones will have been inserted during the namespace
+	     adl.)  */
+	  if (!DECL_ANTICIPATED (fn))
+	    continue;
+
 	  /* Template specializations are never found by name lookup.
 	     (Templates themselves can be found, but not template
 	     specializations.)  */
Index: testsuite/g++.dg/lookup/pr80979.C
===================================================================
--- testsuite/g++.dg/lookup/pr80979.C	(revision 0)
+++ testsuite/g++.dg/lookup/pr80979.C	(working copy)
@@ -0,0 +1,26 @@ 
+// pr C++/80979 ICE with late discovery of using directives during ADL
+// of a friend declaration.
+
+namespace Tiny {
+  class Handsome {};
+  void Dahl (Handsome &, Handsome &);
+
+  namespace Jack {
+    class Vladof {
+      friend void Dahl (Vladof &, Vladof &);
+    };
+    void Dahl (Vladof &, Vladof &);
+  }
+
+  struct BDonk {};
+
+  namespace Tina {
+    void Dahl (BDonk &, Jack::Vladof &);
+  }
+  using Tina::Dahl;
+}
+
+void BoomBoom (Tiny::BDonk &vault, Tiny::Jack::Vladof &hunter)
+{
+  Dahl (vault, hunter);
+}