Search code examples
c++templatesgccc++14function-templates

Unresolved overloaded function type in gcc


I am trying to pass a function template as an argument to another function as seen in the example below.

#include <iostream>

template <typename T>
decltype(auto) foo(T t)
{
    return t;
}

template <typename Fn, typename T>
decltype(auto) bar(Fn fn, T t)
{
    return fn(t);
}

int main()
{
    int arg = 0;

    std::cout << bar(foo<decltype(arg)>, arg) << std::endl;

    return 0;
}

While this works in clang 9.0 and msvc v19.24 it fails with gcc 9.2

gcc output:

no matching function for call to 'bar(<unresolved overloaded function type>, int&)' std::cout << bar(foo<decltype(arg)>, arg) << std::endl;

Is this a bug in gcc? Also can i circumvent this somehow in gcc?

Godbolt link: https://godbolt.org/z/oCChAT


Solution

  • Yes, this is supposed to be a bug of gcc, which has not been fixed even in gcc 10.0.1.

    It seems gcc fails to handling this case when specifying the return type with placeholder type specifiers like auto and decltype(auto). If you specify the return type as T it would work fine.