[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 a5ab703d1d3ffdcd002801e3e6e116f6cb0f9f27..d5141f038473d604d24004b249c81b321ea2424c 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 c76dea46479c06366df6291897106ca48de052fa..43bbf438eaef62c9c02dd1359789e2d0e3fc2e72 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 41099b47ae8bec7f01ded2ac2fcdef747c158b11..58a4c002dc3eac70493906a6b3b3845b86e5e1af 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> ();
+}