The code was already there to give an error for this case, we just weren't hitting it because array_of_runtime_bound_p was incorrectly returning true.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 1106dfa9e9df6e4dddb75c50db57cff953017fc7 Author: Jason Merrill <ja...@redhat.com> Date: Mon Feb 26 20:42:13 2018 -0500 PR c++/84560 - ICE capturing multi-dimensional VLA. * tree.c (array_of_runtime_bound_p): False if the element is variably-modified. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 41d9002d8f9..9b9e36a1173 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1043,6 +1043,8 @@ array_of_runtime_bound_p (tree t) { if (!t || TREE_CODE (t) != ARRAY_TYPE) return false; + if (variably_modified_type_p (TREE_TYPE (t), NULL_TREE)) + return false; tree dom = TYPE_DOMAIN (t); if (!dom) return false; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla2.C new file mode 100644 index 00000000000..d4de131fc23 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla2.C @@ -0,0 +1,12 @@ +// PR c++/84560 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +void f() { + int n = 1; + int m = 1; + int d[n][m]; + [&]() { + return d[1]; // { dg-error "variabl" } + }(); +}