문제

Trying to compile this code:

const int a = 1;
auto lambda = [&]() {
  &a;
};
lambda();

On clang++ everything is fine, but g++ gives an error:

error: lvalue required as unary ‘&’ operand

I haven't found anything explaining such behavior. Is it a bug in g++? Or does clang++ miss something?

도움이 되었습니까?

해결책

It's considered to be a bug in g++: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58894

According to comments, it lasts from GCC 4.5.4 and, at that moment, not fixed in GCC 4.9.0.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top