Unresolved overloaded function type in gcc

Viewed 297

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

2 Answers

For gcc another workaround can be :

auto f = foo<decltype(arg)>;
std::cout << bar(f, arg) << std::endl;
Related