Time for another round of clang vs gcc. Live example on godbolt.org.
Test 0: overloaded callable object
struct Trad
{
auto operator()(int) { return 1; }
auto operator()(float) { return 2; }
auto operator()(double) { return 3; }
};
int main()
{
assert(Trad{}(1) == 1);
assert(Trad{}(1.f) == 2);
assert(Trad{}(1.0) == 3);
}
- g++ 5.2 compiles and run.
- clang++ 3.5 (and later versions) compiles and run.
Test 1: overloaded callable object, generated via lambda inheritance
template <typename... TFs>
struct overload_set : TFs...
{
overload_set(TFs... fs) : TFs(fs)... {}
};
template <typename... TFs>
auto overload(TFs&&... fs)
{
return overload_set<TFs...>{fs...};
}
int main()
{
auto func = overload
(
[](int) { return 1; },
[](float) { return 2; },
[](double) { return 3; }
);
assert(func(1) == 1);
assert(func(1.f) == 2);
assert(func(1.0) == 3);
}
g++ 5.2 does not compile.
error: request for member 'operator()' is ambiguous
clang++ 3.5 (and later versions) compiles and run.
What compiler is correct here?