public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] PR c++/60855 - ICE with sizeof VLA capture.
@ 2020-01-21 23:11 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2020-01-21 23:11 UTC (permalink / raw)
  To: gcc-patches

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.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* lambda.c (is_lambda_ignored_entity): Don't look past VLA capture.
---
 gcc/cp/lambda.c                                 |  5 +++--
 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla4.C | 12 ++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla4.C

diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 50fb144142b..4f39f99756b 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -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
index 00000000000..3e9cf076d14
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla4.C
@@ -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;
+}

base-commit: 8158a4640819dbb3210326e37786fb874f450272
-- 
2.18.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-21 21:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21 23:11 [COMMITTED] PR c++/60855 - ICE with sizeof VLA capture Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).