diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a7ab2bd2887..72bdf869b55 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22120,7 +22120,16 @@ resolve_overloaded_unification (tree tparms, if (subargs != error_mark_node && !any_dependent_template_arguments_p (subargs)) { - elem = TREE_TYPE (instantiate_template (fn, subargs, tf_none)); + fn = instantiate_template (fn, subargs, tf_none); + if (undeduced_auto_decl (fn)) + { + /* Instantiate the function to deduce its return type. */ + ++function_depth; + instantiate_decl (fn, /*defer*/false, /*class*/false); + --function_depth; + } + + elem = TREE_TYPE (fn); if (try_one_overload (tparms, targs, tempargs, parm, elem, strict, sub_strict, addr_p, explain_p) && (!goodfn || !same_type_p (goodfn, elem))) diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn60.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn60.C new file mode 100644 index 00000000000..575abafbae5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn60.C @@ -0,0 +1,11 @@ +// PR c++/64194 +// { dg-do compile { target c++14 } } + +template void g(void (*)(T)) { } + +template auto id(int) { } +template auto id(char) { return 0; } + +int main() { + g(id); +}