]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/55149 (capturing VLA in lambda)
authorJason Merrill <jason@redhat.com>
Fri, 10 May 2013 14:17:30 +0000 (10:17 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 10 May 2013 14:17:30 +0000 (10:17 -0400)
PR c++/55149
* semantics.c (add_capture): Error rather than abort on copy
capture of VLA.
* typeck.c (maybe_warn_about_returning_address_of_local): Don't
warn about capture proxy.

From-SVN: r198776

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

index 8eefe328602a507853b71dcc1d6c317e5f6d885c..ad7235a6e75257e7cb141185ef7f5138c011f32f 100644 (file)
@@ -1,3 +1,11 @@
+2013-05-10  Jason Merrill  <jason@redhat.com>
+
+       PR c++/55149
+       * semantics.c (add_capture): Error rather than abort on copy
+       capture of VLA.
+       * typeck.c (maybe_warn_about_returning_address_of_local): Don't
+       warn about capture proxy.
+
 2013-05-09  Jason Merrill  <jason@redhat.com>
 
        * decl.c (cp_finish_decl): Only check VLA bound in C++1y mode.
index 3e1a0bf281d48124085c8e3432e0ec278663a896..d0db10a03b70d8ce16f36a5a0a12e8294352ee18 100644 (file)
@@ -9463,9 +9463,12 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p,
   type = lambda_capture_field_type (initializer, explicit_init_p);
   if (array_of_runtime_bound_p (type))
     {
+      if (!by_reference_p)
+       error ("array of runtime bound cannot be captured by copy, "
+              "only by reference");
+
       /* For a VLA, we capture the address of the first element and the
         maximum index, and then reconstruct the VLA for the proxy.  */
-      gcc_assert (by_reference_p);
       tree elt = cp_build_array_ref (input_location, initializer,
                                     integer_zero_node, tf_warning_or_error);
       tree ctype = vla_capture_type (type);
index df5fc4a880a10d70c1cd2237c12b357633a0fa7d..b8ea5551353bfcb6944317e74ec416c6614f65da 100644 (file)
@@ -8140,6 +8140,7 @@ maybe_warn_about_returning_address_of_local (tree retval)
   if (DECL_P (whats_returned)
       && DECL_NAME (whats_returned)
       && DECL_FUNCTION_SCOPE_P (whats_returned)
+      && !is_capture_proxy (whats_returned)
       && !(TREE_STATIC (whats_returned)
           || TREE_PUBLIC (whats_returned)))
     {
diff --git a/gcc/testsuite/g++.dg/cpp1y/vla5.C b/gcc/testsuite/g++.dg/cpp1y/vla5.C
new file mode 100644 (file)
index 0000000..1f6da29
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/55149
+// { dg-options -std=c++1y }
+
+void test(int n) {
+  int r[n];
+  [&r]() { return r + 0; };
+  [r]() { return r + 0; };     // { dg-error "captured by copy" }
+}