Clang在折叠表达式中找不到模板二进制运算符 [英] Clang can't find template binary operator in fold expression

查看:67
本文介绍了Clang在折叠表达式中找不到模板二进制运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我连接元组的二进制运算符:

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在折叠表达式中找不到模板二进制运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆