سؤال

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