Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top