public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-9453] c++: overload sets and placeholder return type [PR64194]
@ 2021-04-21 12:25 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-04-21 12:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9499fe0403e310f4eb1f23279bff84259e120e76

commit r9-9453-g9499fe0403e310f4eb1f23279bff84259e120e76
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jul 29 22:06:44 2020 -0400

    c++: overload sets and placeholder return type [PR64194]
    
    In the testcase below, template argument deduction for the call
    g(id<int>) goes wrong because the functions in the overload set id<int>
    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:
---
 gcc/cp/pt.c                            | 11 ++++++++++-
 gcc/testsuite/g++.dg/cpp1y/auto-fn60.C | 11 +++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 104b228187e..cc40ee0bc81 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -21437,7 +21437,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 <typename T> void g(void (*)(T)) { }
+
+template <typename> auto id(int) { }
+template <typename> auto id(char) { return 0; }
+
+int main() {
+  g(id<int>);
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-21 12:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 12:25 [gcc r9-9453] c++: overload sets and placeholder return type [PR64194] Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).