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 +void bar () +{ + T (*p)() = (T (*)(void)) foo; +} + +void +baz () +{ + bar (); +}