这是我连接元组的二进制运算符:
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); }它在两个带有两个元组的编译器(gcc,clang)上都可以完美运行:
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编译时没有任何错误,与clang 5.0不同,它生成错误输出:
gcc 7.1.1 compiles it without any errors, unlike clang 5.0, which produces error output:
错误:调用函数 operator +,该函数在模板定义中不可见,也无法通过依赖于参数的查找找到
error: call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup
return(args + ... );
return (args + ...);
注意:函数的实例化模板专业化'multiple_concat< std :: __ 1 :: tuple& ;, std :: __ 1 :: tuple&>在此处请求
note: in instantiation of function template specialization 'multiple_concat < std::__1::tuple &, std::__1::tuple &>' requested here
multiple_concat (tup1,tup2 );
multiple_concat(tup1, tup2);
注意:'operator +'应该在呼叫站点之前声明
note: 'operator+' should be declared prior to the call site
constexpr decltype(auto) 运算符 +(const std :: tuple& tup1,const std :: tuple& tup2)
constexpr decltype(auto) operator+(const std::tuple &tup1, const std::tuple &tup2)
此代码格式不正确,而clang到底在说什么?
Is this code ill-formed and what exactly is clang talking about?
推荐答案由于其他答案没有出来,这样说:代码很好。这是一个由来已久的 C语 错误,通过11影响版本。
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.
更多推荐
Clang在折叠表达式中找不到模板二进制运算符
发布评论