Commit 5ced939e by Jason Merrill Committed by Jason Merrill

re PR c++/55149 (capturing VLA in lambda)

	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
parent 29554d29
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> 2013-05-09 Jason Merrill <jason@redhat.com>
* decl.c (cp_finish_decl): Only check VLA bound in C++1y mode. * decl.c (cp_finish_decl): Only check VLA bound in C++1y mode.
......
...@@ -9463,9 +9463,12 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p, ...@@ -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); type = lambda_capture_field_type (initializer, explicit_init_p);
if (array_of_runtime_bound_p (type)) 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 /* For a VLA, we capture the address of the first element and the
maximum index, and then reconstruct the VLA for the proxy. */ maximum index, and then reconstruct the VLA for the proxy. */
gcc_assert (by_reference_p);
tree elt = cp_build_array_ref (input_location, initializer, tree elt = cp_build_array_ref (input_location, initializer,
integer_zero_node, tf_warning_or_error); integer_zero_node, tf_warning_or_error);
tree ctype = vla_capture_type (type); tree ctype = vla_capture_type (type);
......
...@@ -8140,6 +8140,7 @@ maybe_warn_about_returning_address_of_local (tree retval) ...@@ -8140,6 +8140,7 @@ maybe_warn_about_returning_address_of_local (tree retval)
if (DECL_P (whats_returned) if (DECL_P (whats_returned)
&& DECL_NAME (whats_returned) && DECL_NAME (whats_returned)
&& DECL_FUNCTION_SCOPE_P (whats_returned) && DECL_FUNCTION_SCOPE_P (whats_returned)
&& !is_capture_proxy (whats_returned)
&& !(TREE_STATIC (whats_returned) && !(TREE_STATIC (whats_returned)
|| TREE_PUBLIC (whats_returned))) || TREE_PUBLIC (whats_returned)))
{ {
......
// 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" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment