The following code (reduced for context) is taken from n3092 [expr.prim.lambda], 5.1.2/13, where it states:
"A lambda expression appearing in a default argument shall not implicitly or explicitly capture and entity." /cygdrive/d/CPPProjects/nano/gcc_bugs $cat _5_1_2_13.cpp // file: _5_1_2_13.cpp void f2() { int i = 1; // ... void g5(int = ([]{ return sizeof i; })()); } gcc-4.5.0 fails this code with the following error messages. 12:51:47 Paul bibbi...@jijou /cygdrive/d/CPPProjects/nano/gcc_bugs $i686-pc-cygwin-gcc-4.5.0 -Wall -save-temps -std=c++0x -c _5_1_2_13.cpp _5_1_2_13.cpp: In lambda function: _5_1_2_13.cpp:6:37: error: local variable i may not appear in this context _5_1_2_13.cpp:6:40: error: return-statement with a value, in function returning 'void' _5_1_2_13.cpp: In function void f2(): _5_1_2_13.cpp:6:44: error: default argument for int <anonymous> has type void _5_1_2_13.cpp:4:8: warning: unused variable i Appearance of the local variable i in this context is valid on the grounds that, in the first instance, the operand to sizeof is an unevaluated operand (as per 5.3.3./1 [expr.sizeof]) and hence (as per 3.2/2 [basic.def.odr]) its presence here does not constitute a use (which would otherwise require it to be explicitly or implicitly captured, the latter according to 5.1.2/11). However, 5.1.2/7 should still apply - "The lambda-expression's compound-statement yields the function body (8.4) of the function call operator, but for the purposes of name lookup (3.4), [...] the compound-statement is considered in the context of the lambda-expression." 12:54:21 Paul bibbi...@jijou /cygdrive/d/CPPProjects/nano/gcc_bugs $i686-pc-cygwin-gcc-4.5.0 -v Using built-in specs. COLLECT_GCC=i686-pc-cygwin-gcc-4.5.0 COLLECT_LTO_WRAPPER=/opt/gcc-4.5.0/libexec/gcc/i686-pc-cygwin/4.5.0/lto-wrapper.exe Target: i686-pc-cygwin Configured with: ./configure --prefix=/opt/gcc-4.5.0 --enable-bootstrap --enable-version-specific-runtime-libs --enable-static --enable-shared --enable-shared-libgcc --disable-__cxa_atexit --with-gnu-ld --with-gnu-as --with-dwarf2 --disable-sjlj-exceptions --enable-languages=c,c++ --disable-symvers --enable-libgomp --enable-libssp --enable-threads=posix --with-arch-i686 --with-tune=generic Thread model: posix gcc version 4.5.0 (GCC) -- Summary: [C++0x] name lookup failure on un-used local variable in lambda compound-statement Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: paul dot bibbings at gmail dot com GCC host triplet: i686-pc-cygwin http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43886