As pointed out by ecatmur, this question already has an answer here.
This question is obviously not a duplicate of trailing return type using decltype with a variadic template function. It actually tries to propose a simpler solution to address the issue in that thread. The question is whether this solution is correct according to the standard, because GCC and clang disagree on it. Just read the question a little more carefully, and you will realize that.
This question is inspired by this one. I'm trying to come up with a simpler solution than the ones already provided, and end up with this:
#include <iostream>
struct S {
template <typename T>
static T sum(T t){
return t;
}
template <typename T, typename ...U>
static auto sum(T t, U... u) -> decltype(t + sum(u...)) {
return t + sum(u...);
}
};
int main() {
std::cout << S::sum(1, 1.5, 2) << '\n';
}
While this solution works with GCC, it does not solve the problem at all on clang. So, I'm wondering which one is correct.