Why does the following code produce error: no viable constructor or deduction guide for deduction of template arguments of 'R'?
I've tried compiling this code on gcc.godbolt.org using all versions of Clang starting from 6.0.0 and up. They all produce the same error message. However, the code compiles with GCC 8.1 and later. Could this be a bug in Clang? Or maybe in GCC?
Compiler options used: -std=c++17 -O2 -Wall -Wextra
#include <functional>
template <typename T>
int fn(T&)
{
return 0;
}
struct S {};
template <typename T>
struct R
{
using F = std::function<int(T&)>;
R(T& _t, F _fn)
: t_{_t}
, fn_{_fn}
{
fn_(t_);
}
T& t_;
F fn_;
};
int main()
{
S s;
// Why does Clang fail on 'fn<S>'?
// If I wrap 'fn<S>' in curly braces (e.g. {fn<S>}), it works.
R r{s, fn<S>};
return 0;
}