http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53157
Bug #: 53157 Summary: within lambda, error: lvalue required as unary ‘&’ operand Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: m...@g.clemson.edu the following code failed to compile with g++-4.7.0 ------------------- BEGIN ------------------- void f(const int*) { } void g() { const int N = 10; [=] { int arr[N]; // OK: not an odr-use, refers to automatic variable f(&N); // OK: causes N to be captured; &N points to the // corresponding member of the closure type } } int main () { return 0; } ------------------- BEGIN ------------------- the f and g are copied from c++11 5.1.2/17. compiled with : ~/gcc/4.7.0/bin/c++ --std=c++11 -Wall t1.cc g++-4.7.0 gives me two errors : (1) for the call to f(&N); : error: lvalue required as unary ‘&’ operand (2) at the end of the lambda : error: expected ‘;’ before ‘}’ token the standard says that the use of f(&N) is valid because the N is odr-used and should be implicitly captured by value, so &N returns a pointer to the data member of the closure type that is a copy of the original N. my g++ -v is : Reading specs from /home/meng/gcc/4.7.0/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/specs COLLECT_GCC=/home/meng/gcc/4.7.0/bin/c++ COLLECT_LTO_WRAPPER=/home/meng/gcc/4.7.0/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ./configure --prefix=/home/meng/gcc/4.7.0 --enable-languages=c,c++ -disable-multilib Thread model: posix gcc version 4.7.0 (GCC) my uname -a is : Linux meng-laptop 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:12:07 UTC 2012 x86_64 GNU/Linux