Bug 64194 - [C++14] <unresolved overloaded function type> for function template with auto return
Summary: [C++14] <unresolved overloaded function type> for function template with auto...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 10.3
Assignee: Patrick Palka
URL:
Keywords: rejects-valid
: 54111 69260 78882 85499 85554 86826 93317 96361 97778 97999 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-12-05 15:12 UTC by Jonathan Wakely
Modified: 2021-07-27 07:14 UTC (History)
13 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-06-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2014-12-05 15:12:07 UTC
template <typename Tp> auto id() { }

template <typename T> void g(T) { }

int main()
{
    // id<int>;
    g(id<int>);
}

G++ fails to resolve id<int> in the call.

over.cc: In function ‘int main()’:
over.cc:8:14: error: no matching function for call to ‘g(<unresolved overloaded function type>)’
     g(id<int>);
              ^
over.cc:3:28: note: candidate: template<class T> void g(T)
 template <typename T> void g(T) { }
                            ^
over.cc:3:28: note:   template argument deduction/substitution failed:
over.cc:8:14: note:   couldn't deduce template parameter ‘T’
     g(id<int>);
              ^

It works if the reference to id<int> is uncommented, or if auto id() is changed to void id()
Comment 1 Jonathan Wakely 2016-12-21 14:06:15 UTC
*** Bug 78882 has been marked as a duplicate of this bug. ***
Comment 2 lcid-fire 2016-12-21 14:12:01 UTC
Shouldn't the status be confirmed?
Comment 3 Jonathan Wakely 2016-12-21 14:22:17 UTC
It is confirmed, and has been since 2014-12-08. If you look at the dropdown you'll see there is no CONFIRMED status in GCC's bugzilla.
Comment 4 Jonathan Wakely 2017-06-28 14:21:01 UTC
(In reply to Jonathan Wakely from comment #0)
> It works if the reference to id<int> is uncommented, or if auto id() is
> changed to void id()

Or by adding something else to trigger the instantiation of the right specialization, e.g.

    using F = decltype(id<int>);

Slightly reduced (it doesn't matter if g has a deduced return type):


template <typename Tp> auto id() { }

template <typename T> void g(T) { }

int main()
{
    // id<int>;
    // using F = decltype(id<int>);
    g(id<int>);
}
Comment 5 Jonathan Wakely 2017-06-28 14:22:44 UTC
(In reply to Jonathan Wakely from comment #4)
> Slightly reduced (it doesn't matter if g has a deduced return type):

Oops, it already wasn't deduced ... I confused myself with a new testcase I was trying!
Comment 6 Jonathan Wakely 2018-04-23 09:45:34 UTC
*** Bug 85499 has been marked as a duplicate of this bug. ***
Comment 7 Jonathan Wakely 2018-04-23 09:47:21 UTC
*** Bug 69260 has been marked as a duplicate of this bug. ***
Comment 8 Jonathan Wakely 2018-04-23 09:49:05 UTC
Slightly different testcase from PR 69620 which is probably the same issue:

struct function {
  template<typename F>
    function(F);
};

template <typename T1, typename T2>
auto sum(T1 x, T2 y)
{
    return x + y;
}

template <typename T1, typename T2, typename... Targ>
auto sum(T1 x, T2 y, Targ... args)
{
    return sum(x + y, args...);
}

int main()
{
    //(void)sum<int, int, int>;
    function f = sum<int, int, int>;
}

ded.cc: In function 'int main()':
ded.cc:21:18: error: conversion from '<unresolved overloaded function type>' to non-scalar type 'function' requested
     function f = sum<int, int, int>;
                  ^~~~~~~~~~~~~~~~~~


It works if the function is instantiated first by uncommenting the first line in main.
Comment 9 Jonathan Wakely 2018-04-27 23:14:16 UTC
*** Bug 85554 has been marked as a duplicate of this bug. ***
Comment 10 Patrick Palka 2020-07-29 12:57:35 UTC
*** Bug 96361 has been marked as a duplicate of this bug. ***
Comment 11 GCC Commits 2020-07-30 02:15:28 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:2c58f5cadfac338a67723fd6e41c9097760c4a33

commit r11-2420-g2c58f5cadfac338a67723fd6e41c9097760c4a33
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.
Comment 12 Patrick Palka 2020-08-03 14:51:30 UTC
Should be fixed for GCC 11, thanks for the reports.
Comment 13 Jonathan Wakely 2020-09-02 16:33:51 UTC
*** Bug 93317 has been marked as a duplicate of this bug. ***
Comment 14 Jonathan Wakely 2020-11-10 13:24:48 UTC
*** Bug 97778 has been marked as a duplicate of this bug. ***
Comment 15 Jonathan Wakely 2020-12-08 10:32:55 UTC
*** Bug 54111 has been marked as a duplicate of this bug. ***
Comment 16 Jason Merrill 2020-12-08 22:44:36 UTC
The fix looks safe to backport; it isn't a regression, but the number of duplicate reports argue for making an exception.
Comment 17 GCC Commits 2020-12-10 14:25:22 UTC
The releases/gcc-10 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:4fb1ee669ccaad16795baf25d2cab48d8cf8c1eb

commit r10-9136-g4fb1ee669ccaad16795baf25d2cab48d8cf8c1eb
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)
Comment 18 Jonathan Wakely 2021-03-08 10:08:03 UTC
*** Bug 86826 has been marked as a duplicate of this bug. ***
Comment 19 GCC Commits 2021-04-21 12:25:06 UTC
The releases/gcc-9 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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)
Comment 20 Andrew Pinski 2021-07-27 07:14:50 UTC
*** Bug 97999 has been marked as a duplicate of this bug. ***