diff mbox

C++ PATCH for c++/59271 (ICE with polymorphic lambda and VLA)

Message ID 52B90AEB.7020902@redhat.com
State New
Headers show

Commit Message

Jason Merrill Dec. 24, 2013, 4:17 a.m. UTC
This testcase was crashing in strip_typedefs because it uses 
build_cplus_array_type, while the original type was built with the 
generic build_array_type, and the two functions work differently within 
a template such that we violated an assert in strip_typedefs.  Fixed by 
using build_cplus_array_type consistently.

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

Patch

commit 9e0c771b79ce3c143fffae2fd09ecdc6f88041d9
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Dec 23 15:20:38 2013 -0500

    	PR c++/59271
    	* lambda.c (build_capture_proxy): Use build_cplus_array_type.

diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 24aa2c5..bd8df1d 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -377,8 +377,8 @@  build_capture_proxy (tree member)
       tree ptr = build_simple_component_ref (object, field);
       field = next_initializable_field (DECL_CHAIN (field));
       tree max = build_simple_component_ref (object, field);
-      type = build_array_type (TREE_TYPE (TREE_TYPE (ptr)),
-			       build_index_type (max));
+      type = build_cplus_array_type (TREE_TYPE (TREE_TYPE (ptr)),
+				     build_index_type (max));
       type = build_reference_type (type);
       REFERENCE_VLA_OK (type) = true;
       object = convert (type, ptr);
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-vla1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-vla1.C
new file mode 100644
index 0000000..556722c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-vla1.C
@@ -0,0 +1,24 @@ 
+// PR c++/59271
+// { dg-options -std=c++1y }
+
+extern "C" int printf (const char *, ...);
+
+void f(int n)
+{
+  int  a[n];
+
+  for (auto& i : a)
+    {
+      i = &i - a;
+    }
+
+  [&a] (auto m)
+    {
+      for (auto i : a)
+	{
+	  printf ("%d", i);
+	}
+
+      return m;
+    };
+}