Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang can't find template binary operator in fold expression

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?

like image 343
Максим Шапошников Avatar asked Nov 08 '22 18:11

Максим Шапошников


1 Answers

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.

like image 109
Davis Herring Avatar answered Nov 14 '22 23:11

Davis Herring