This fixes 83287, a case where we failed to mark a lookup occuring inside a template definition as being kept for instantiation. It turns out that CAST_EXPR's single argument is a TREE_LIST, so we need to check it for OVERLOADS. CAST_EXPR behaves this way because it's modelling a function call. AFAICT it is the only node of this form.

applying to trunk.

nathan
--
Nathan Sidwell
Index: cp/tree.c
===================================================================
--- cp/tree.c	(revision 255420)
+++ cp/tree.c	(working copy)
@@ -3230,6 +3230,13 @@ build_min (enum tree_code code, tree tt,
     }
 
   va_end (p);
+
+  if (code == CAST_EXPR)
+    /* The single operand is a TREE_LIST, which we have to check.  */
+    for (tree v = TREE_OPERAND (t, 0); v; v = TREE_CHAIN (v))
+      if (TREE_CODE (TREE_VALUE (v)) == OVERLOAD)
+	lookup_keep (TREE_VALUE (v), true);
+
   return t;
 }
 
Index: testsuite/g++.dg/lookup/pr83287.C
===================================================================
--- testsuite/g++.dg/lookup/pr83287.C	(revision 0)
+++ testsuite/g++.dg/lookup/pr83287.C	(working copy)
@@ -0,0 +1,19 @@
+// PR c++/83287 failed to keep lookup until instantiation time
+
+void foo ();
+
+namespace {
+  void foo (int);
+}
+
+template <class T>
+void bar ()
+{
+  T (*p)() = (T (*)(void)) foo;
+}
+
+void
+baz ()
+{
+  bar<void> ();
+}

Reply via email to