折叠表达式和函数名称查找
fold expression and function name lookup
我正在学习 C++17 中的折叠表达式。我有以下代码
#include <iostream>
#include <vector>
namespace io {
template<typename T>
std::istream &operator>>(std::istream &in, std::vector<T> &vec) {
for (auto &x : vec)
in >> x;
return in;
}
template<class... Args> void scan(Args &... args) {
(std::cin >> ... >> args);
}
}// namespace io
int main() {
std::vector<int> s(1), t(1);
io::scan(s, t);
std::cout << s[0] << ' ' << t[0] << 'n';
}
使用GCC 9.3.0,代码可以正确编译和运行,但使用 Clang 10.0.0,相同的代码无法编译:
<source>:13:16: error: call to function 'operator>>' that is neither visible in the template definition nor found by argument-dependent lookup
(std::cin >> ... >> args);
^
<source>:19:9: note: in instantiation of function template specialization 'io::scan<std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> > >' requested here
io::scan(s, t);
^
<source>:6:15: note: 'operator>>' should be declared prior to the call site
std::istream &operator>>(std::istream &in, std::vector<T> &vec) {
^
1 error generated.
为什么 clang 重新喷射代码,而 gcc 接受它?
这是一个Clang错误。Clang 版本 11 及更早版本未正确实现折叠表达式中运算符的两阶段名称查找,并且会错误地从恰好执行折叠表达式实例化的词法范围执行第一阶段查找,而不是从模板定义的上下文执行第一阶段查找。
我最近才修复此问题(不幸的是没有赶上即将发布的 Clang 11 版本(,并且测试用例现在被 Clang 主干接受。
相关文章:
- 递归ASMVisitor 和查找函数调用站点
- C++ - 查找函数无法在子字符串上执行
- 查找函数是否为常量
- GDB 如何查找函数退出的位置
- 查找函数在unordered_map中的工作方式是搜索键值
- 在 C++ <algorithm>中查找函数
- 错误:二进制表达式的操作数无效(映射使用查找函数错误)
- 哪个查找规则阻止编译器查找函数
- 在C++中查找函数的调用方(Visual Studio)
- 关于获取行和字符串查找函数的问题
- 查找函数在失败结果中应该返回什么
- 如何使用调用和别名指令在 llvm 字节码中查找函数名称
- std::字符串类查找函数不返回预期结果.我可能用错了
- 在成对向量中查找函数时出错
- 从堆栈指针中查找函数参数值
- 如何定义查找函数
- 如何查找函数是否可重入
- 在c++中查找函数
- GNU g++ 4.9.2 查找函数调用的编译错误
- 使用GDB查找函数对应的内存地址/调试