c++ - Clang 在折叠表达式中找不到模板二元运算符

标签 c++ templates variadic-templates c++17

这是我用来连接元组的二元运算符:

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);
}

它在带有两个元组的两个编译器(gcc、clang)上都能完美运行:

template <class Arg1, class Arg2>
constexpr decltype(auto) concat_test(Arg1 &&arg1, Arg2 &&arg2) {
   return arg1 + arg2;
}

但是当我尝试在折叠表达式中使用它时,如下所示:

template <class... Args>
constexpr decltype(auto) multiple_concat(Args &&... args) {
   return (args + ...);
}

gcc 7.1.1 编译它没有任何错误,不像 clang 5.0,它会产生错误输出:

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)

这段代码格式不正确吗?clang 到底在说什么?

最佳答案

既然其他答案不出来这么说:代码没问题。这是一个长期的Clang bug ,影响到 11 的版本。

关于c++ - Clang 在折叠表达式中找不到模板二元运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45569698/

相关文章:

c++ - 使用 msvc 时,有没有办法获得有关错误上下文的更好信息? (例如 : C2248)

c++ - 是否可以使用模板类的单个参数将类型和该类型的指针传递给 C++ 模板类?

C++ 模板元编程 : find out if variadic type list contains value

c++ - 为什么 boost::any 禁止转发 const&&?

c++ - 如何 typedef 具有未指定大小的 std::array?

c++ - 如何在 Visual Studio 中设置 MPI 中的进程数?

c++ - 为什么 const 在这个模板结构中丢失了?

c++ - 编写类型特征以检测 Eigen 中的矩阵表达式

c++ - 获取 std::function 的可变参数模板参数类型的自定义 sizeof

c++ - 在 C++11 中,... 是否被视为运算符?