作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
关于 lambda 的部分捕获 ([expr.prim.lambda.capture]/5 ) 声明
If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.
考虑以下示例:
#include <iostream>
int main ()
{
auto foo = 1234;
auto bar = [foo](int foo) { std::cout << foo << '\n'; };
bar(4321);
}
最新的 GCC 版本(8.2.0 - 2018 年 7 月 26 日发布)对此没有诊断。最新的 Clang 版本(7.0.0 - 2018 年 9 月 19 日发布)也没有。
这些编译器是否应该有诊断(错误/警告)(如前所述在引用)沿线:
// parameter and simple-capture have the same name
Godbolt 演示 here
最佳答案
该措辞已添加到 C++17 以解决 CWG Defect 2211 .它在 C++14 中不存在,而且 Clang 和 GCC 似乎还没有 catch 你正在检查的版本的这种变化。
值得注意的是,GCC 主干确实将该程序诊断为 C++17 下的格式错误。
关于c++ - 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52947934/
我是一名优秀的程序员,十分优秀!