PR c++/60855 - ICE with sizeof VLA capture.
authorJason Merrill <jason@redhat.com>
Tue, 21 Jan 2020 19:21:49 +0000 (14:21 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 21 Jan 2020 21:42:10 +0000 (16:42 -0500)
For normal captures we usually look through them within unevaluated context,
but that doesn't work here; trying to take the sizeof of the array in the
enclosing scope tries and fails to evaluate a SAVE_EXPR from the enclosing
scope.

* lambda.c (is_lambda_ignored_entity): Don't look past VLA capture.

gcc/cp/ChangeLog
gcc/cp/lambda.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla4.C [new file with mode: 0644]

index cfc9c62371f36e9c540329e5d203919bff7e282b..04c5d2ee8f48eff0e16373133ea1995ced15b16c 100644 (file)
@@ -1,5 +1,8 @@
 2020-01-21  Jason Merrill  <jason@redhat.com>
 
+       PR c++/60855 - ICE with sizeof VLA capture.
+       * lambda.c (is_lambda_ignored_entity): Don't look past VLA capture.
+
        PR c++/90732 - ICE with VLA capture and generic lambda.
        * pt.c (tsubst_lambda_expr): Repeat add_capture for VLAs.
 
index 50fb144142b34f8ac96d545ea3bb42055d8b92f2..4f39f99756bb00da9782c372b0f35d005532940e 100644 (file)
@@ -1327,8 +1327,9 @@ lambda_static_thunk_p (tree fn)
 bool
 is_lambda_ignored_entity (tree val)
 {
-  /* Look past normal capture proxies.  */
-  if (is_normal_capture_proxy (val))
+  /* Look past normal, non-VLA capture proxies.  */
+  if (is_normal_capture_proxy (val)
+      && !variably_modified_type_p (TREE_TYPE (val), NULL_TREE))
     return true;
 
   /* Always ignore lambda fields, their names are only for debugging.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla4.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla4.C
new file mode 100644 (file)
index 0000000..3e9cf07
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/60855
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wno-vla" }
+
+int main() {
+  unsigned count = 5;
+  bool array[count];
+  [&array] () {
+    array[0] = sizeof(array) > 5;
+  }();
+  return 0;
+}