summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-10 14:17:30 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-10 14:17:30 +0000
commit4da0e4efd238e5c3d7ba110af1bb3cf39c138c2c (patch)
tree2ac5e103ad1302783fb5637466fda43a9c36c25d
parenta30c75403137b35a77e4d7a0b8292c8ee46ff1d1 (diff)
downloadppe42-gcc-4da0e4efd238e5c3d7ba110af1bb3cf39c138c2c.tar.gz
ppe42-gcc-4da0e4efd238e5c3d7ba110af1bb3cf39c138c2c.zip
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198776 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/semantics.c5
-rw-r--r--gcc/cp/typeck.c1
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/vla5.C8
4 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8eefe328602..ad7235a6e75 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 3e1a0bf281d..d0db10a03b7 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index df5fc4a880a..b8ea5551353 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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
index 00000000000..1f6da290487
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/vla5.C
@@ -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" }
+}
OpenPOWER on IntegriCloud