re PR c++/55520 ([C++11] ICE when capturing a variable-length stack array in lambda...
authorJason Merrill <jason@redhat.com>
Fri, 7 Jun 2013 03:13:06 +0000 (23:13 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 7 Jun 2013 03:13:06 +0000 (23:13 -0400)
PR c++/55520
* semantics.c (add_capture): Diagnose capture of variable-size
type that is not a C++1y array of runtime bound.

From-SVN: r199780

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp1y/vla7.C [new file with mode: 0644]

index c53a9ff0b5a0df639a119e0bfac34530f1d88198..83e6e87190d1baf2a9ed0aac43ba338be96547b3 100644 (file)
@@ -1,5 +1,9 @@
 2013-06-06  Jason Merrill  <jason@redhat.com>
 
+       PR c++/55520
+       * semantics.c (add_capture): Diagnose capture of variable-size
+       type that is not a C++1y array of runtime bound.
+
        * decl.c (grokdeclarator): Keep a decl with error type.
        (grokfield, grokbitfield): Likewise.
        * pt.c (instantiate_class_template_1): Likewise.
index 048a7db5e1e52abf4c527bbdb1a1508fb825fe69..b5c3b0a1fefd3c523206f822191fa2afd3be7b20 100644 (file)
@@ -9487,6 +9487,15 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p,
                                          nelts_field, array_type_nelts (type));
       type = ctype;
     }
+  else if (variably_modified_type_p (type, NULL_TREE))
+    {
+      error ("capture of variable-size type %qT that is not a C++1y array "
+            "of runtime bound", type);
+      if (TREE_CODE (type) == ARRAY_TYPE
+         && variably_modified_type_p (TREE_TYPE (type), NULL_TREE))
+       inform (input_location, "because the array element type %qT has "
+               "variable size", TREE_TYPE (type));
+    }
   else if (by_reference_p)
     {
       type = build_reference_type (type);
diff --git a/gcc/testsuite/g++.dg/cpp1y/vla7.C b/gcc/testsuite/g++.dg/cpp1y/vla7.C
new file mode 100644 (file)
index 0000000..df34c82
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/55520
+// { dg-options "-Wno-vla" }
+// { dg-require-effective-target c++11 }
+
+int main(int argc, char** argv)
+{
+  int x[1][argc];
+
+  [&x](int i) {                        // { dg-error "variable.size" }
+    x[0][i] = 0;               // { dg-prune-output "assignment" }
+  }(5);
+}