Clang在折叠表达式中找不到模板二进制运算符

编程入门 行业动态 更新时间:2024-10-12 01:32:27
本文介绍了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在折叠表达式中找不到模板二进制运算符

本文发布于:2023-11-06 03:51:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562652.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   中找   运算符   模板   Clang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!