如果对象没有复制构造函数,lambda 捕获将失败(在 MSVC 上)

lambda capture fails (on MSVC) if object has no copy constructor

Code to reproduce:

struct S
{
    S();
    S(S const&) = delete;
};

auto x = [s = S()]{};

看起来 MSVC 在构建 lambda 时不适用(在 C++17 中是强制性的?)复制省略。这破坏了我的一些代码...

VC的行为是否违反标准?

根据“语言律师”的评论:这是 MSVC 中的一个 known bug,已在 VS19 v16.2 和 VS17 v15.8 中修复。不幸的是(截至目前)修复仅适用于 /std:c++latest.