From: Patrick Palka Date: Thu, 30 Jul 2020 02:06:44 +0000 (-0400) Subject: c++: overload sets and placeholder return type [PR64194] X-Git-Tag: releases/gcc-10.3.0~528 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fb1ee669ccaad16795baf25d2cab48d8cf8c1eb;p=thirdparty%2Fgcc.git c++: overload sets and placeholder return type [PR64194] In the testcase below, template argument deduction for the call g(id) goes wrong because the functions in the overload set id each have a yet-undeduced auto return type, and this undeduced return type makes try_one_overload fail to match up any of the overloads with g's parameter type, leading to g's template argument going undeduced and to the overload set going unresolved. This patch fixes this issue by performing return type deduction via instantiation before doing try_one_overload, in a manner similar to what resolve_address_of_overloaded_function does. gcc/cp/ChangeLog: PR c++/64194 * pt.c (resolve_overloaded_unification): If the function template specialization has a placeholder return type, then instantiate it before attempting unification. gcc/testsuite/ChangeLog: PR c++/64194 * g++.dg/cpp1y/auto-fn60.C: New test. (cherry picked from commit 2c58f5cadfac338a67723fd6e41c9097760c4a33) --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7bbd9d1f55e2..0879989c2873 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22240,6 +22240,13 @@ resolve_overloaded_unification (tree tparms, fn = instantiate_template (fn, subargs, tf_none); if (!constraints_satisfied_p (fn)) continue; + 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, 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 000000000000..575abafbae51 --- /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); +}