All 4.8.x and later ICE, but not 4.7.x. The code is correctly accepted by Clang. $ g++-trunk -v Using built-in specs. COLLECT_GCC=g++-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap Thread model: posix gcc version 7.0.1 20170203 (experimental) [trunk revision 245148] (GCC) $ $ clang++ -c -std=c++11 small.cpp $ $ g++-trunk -c -std=c++11 small.cpp small.cpp: In lambda function: small.cpp:6:5: error: Local declaration from a different function [&] { decltype (b) c; } (); ^ D.2056 small.cpp:6:22: note: in statement [&] { decltype (b) c; } (); ^ _1 = (sizetype) D.2056; small.cpp:6:5: error: Local declaration from a different function [&] { decltype (b) c; } (); ^ D.2056 small.cpp:6:22: note: in statement [&] { decltype (b) c; } (); ^ _5 = (sizetype) D.2056; small.cpp:6:5: internal compiler error: verify_gimple failed [&] { decltype (b) c; } (); ^ 0xe5e15d verify_gimple_in_cfg(function*, bool) ../../gcc-source-trunk/gcc/tree-cfg.c:5266 0xd3ac27 execute_function_todo ../../gcc-source-trunk/gcc/passes.c:1966 0xd3b595 execute_todo ../../gcc-source-trunk/gcc/passes.c:2016 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. $ ----------------------------------- int a = 1; void foo () { int b[a]; [&] { decltype (b) c; } (); }
Confirmed, also 4.7.0 (with checking enabled) ICEs.
Related to PR60230 and PR64000.
This is not valid C++11 code: b (and thus c) are VLAs, which are not part of any C++ standard. But we should still accept it. G++ currently has trouble with outer VLA types that aren't simple "array of runtime bound" from the cancelled Arrays TS.
Since r10-6389 we no longer crash but issue an error: 79367.C: In lambda function: 79367.C:6:22: error: ‘c’ declared as reference but not initialized 6 | [&] { decltype (b) c; } (); | ^