Patchwork C++ PATCH for c++/57408 (ICE with invalid VLA capture)

login
register
mail settings
Submitter Jason Merrill
Date June 27, 2013, 2:30 a.m.
Message ID <51CBA3E1.4040101@redhat.com>
Download mbox | patch
Permalink /patch/254929/
State New
Headers show

Comments

Jason Merrill - June 27, 2013, 2:30 a.m.
We already added a helpful error message for this case, but we should 
also avoid crashing.

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

Patch

commit b87fed16be1aad58770349909ab8045088ed28ff
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 21 08:28:49 2013 -0400

    	PR c++/57408
    	* semantics.c (add_capture): Set type to error_mark_node after
    	error.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 0a460a4..4c76b80 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9521,6 +9521,7 @@  add_capture (tree lambda, tree id, tree initializer, bool by_reference_p,
 	  && variably_modified_type_p (TREE_TYPE (type), NULL_TREE))
 	inform (input_location, "because the array element type %qT has "
 		"variable size", TREE_TYPE (type));
+      type = error_mark_node;
     }
   else if (by_reference_p)
     {
diff --git a/gcc/testsuite/g++.dg/cpp1y/vla9.C b/gcc/testsuite/g++.dg/cpp1y/vla9.C
new file mode 100644
index 0000000..ea5c4d8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/vla9.C
@@ -0,0 +1,31 @@ 
+// PR c++/57408
+// { dg-options "-std=c++1y -pedantic-errors" }
+
+template<typename Callable>
+  struct Impl
+  {
+    Callable func;
+    Impl(Callable f) : func(f) { }
+    virtual void run() { func(); }
+  };
+
+template<typename Callable>
+void call(Callable f)
+  {
+    Impl<Callable>(f).run();
+  }
+
+extern "C" int printf(const char*, ...);
+
+int main(){
+    int y = 2;
+    float fa[2][y];	    // { dg-error "array of array of runtime bound" }
+    fa[0][0]=0.8;
+    fa[0][1]=1.8;
+    auto fx=[&](){
+        for(int c=0; c<2; c++){
+            printf("use me", fa[0][c]);	// { dg-error "capture of variable-size type" }
+        }
+    };
+    call(fx);
+}