[PR C++/83287] Mark lookup for keeping
authorNathan Sidwell <nathan@acm.org>
Tue, 5 Dec 2017 17:29:58 +0000 (17:29 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 5 Dec 2017 17:29:58 +0000 (17:29 +0000)
https://gcc.gnu.org/ml/gcc-patches/2017-12/msg00242.html
PR c++/83287
* tree.c (build_min): Check CAST_EXPR arg for OVERLOADs.

* g++.dg/lookup/pr83287.C: New.

From-SVN: r255429

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/pr83287.C [new file with mode: 0644]

index a5ab703..d5141f0 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-05  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/83287
+       * tree.c (build_min): Check CAST_EXPR arg for OVERLOADs.
+
 2017-12-05  Martin Liska  <mliska@suse.cz>
            Jakub Jelinek  <jakub@redhat.com>
 
index c76dea4..43bbf43 100644 (file)
@@ -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 41099b4..58a4c00 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-05  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/83287
+       * g++.dg/lookup/pr83287.C: New.
+
 2017-12-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR testsuite/83289
diff --git a/gcc/testsuite/g++.dg/lookup/pr83287.C b/gcc/testsuite/g++.dg/lookup/pr83287.C
new file mode 100644 (file)
index 0000000..305407b
--- /dev/null
@@ -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> ();
+}