We already handle stripping dereferences for non-VLA captures, just need to do the same thing for VLAs in the case of a nested capture.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 95a82187a0986740f6357f74ba6d03814ba7fc1c Author: Jason Merrill <ja...@redhat.com> Date: Sun Feb 18 23:57:57 2018 -0500 PR c++/84429 - ICE capturing VLA. * lambda.c (build_capture_proxy): Handle reference refs. diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 38500b13262..a0a80dfde5c 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -451,11 +451,12 @@ build_capture_proxy (tree member, tree init) { if (PACK_EXPANSION_P (init)) init = PACK_EXPANSION_PATTERN (init); - if (INDIRECT_REF_P (init)) - init = TREE_OPERAND (init, 0); - STRIP_NOPS (init); } + if (INDIRECT_REF_P (init)) + init = TREE_OPERAND (init, 0); + STRIP_NOPS (init); + gcc_assert (VAR_P (init) || TREE_CODE (init) == PARM_DECL); while (is_normal_capture_proxy (init)) init = DECL_CAPTURED_VARIABLE (init); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla1.C new file mode 100644 index 00000000000..91498c4589a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla1.C @@ -0,0 +1,9 @@ +// PR c++/84429 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +void foo(int i) +{ + char x[i]; + [&]{ [&]{ return x; }; }; +}