考虑以下计划:
#include <iostream>
struct X {
X () = default;
X (X &) { std::cout << "non-const called" << std::endl; }
X (X const &) { std::cout << "const called" << std::endl; }
int i () const { return 7; }
};
auto f () {
X x;
auto lambda = [=]() { return x.i(); };
return lambda;
}
int main()
{
auto lambda = f();
std::cout << lambda () << std::endl;
return 0;
}
使用VC ++ 15,我得到了输出
const called
const called
7
使用Clang 3.9,我得到了
non-const called
7
这里的编译器是正确的吗?