This is my binary operator to concatenate tuples:
template <class... Args1, class... Args2>
constexpr decltype(auto) operator+(const std::tuple<Args1...> &tup1,
const std::tuple<Args2...> &tup2) {
return std::tuple_cat(tup1, tup2);
}
It works perfectly on both compiler (gcc, clang) with two tuples:
template <class Arg1, class Arg2>
constexpr decltype(auto) concat_test(Arg1 &&arg1, Arg2 &&arg2) {
return arg1 + arg2;
}
But when I try to use it in fold expression like follows:
template <class... Args>
constexpr decltype(auto) multiple_concat(Args &&... args) {
return (args + ...);
}
gcc 7.1.1 compiles it without any errors, unlike clang 5.0, which produces error output:
error: call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup
return (args + ...);
note: in instantiation of function template specialization 'multiple_concat < std::__1::tuple &, std::__1::tuple &>' requested here
multiple_concat(tup1, tup2);
note: 'operator+' should be declared prior to the call site
constexpr decltype(auto) operator+(const std::tuple &tup1, const std::tuple &tup2)
Is this code ill-formed and what exactly is clang talking about?
Since the other answers don’t come out and say this: the code is fine. This is a longstanding Clang bug, affecting versions through 11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With