Commit 0c018b6f by Paolo Carlini Committed by Paolo Carlini

re PR c++/61088 (segfault with array of lambdas initialized with initializer…

re PR c++/61088 (segfault with array of lambdas initialized with initializer list that contains a lambda that captures the array)

/cp
2014-05-22  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/61088
	* lambda.c (add_capture): Enforce that capture by value requires
	complete type.
	* typeck2.c (cxx_incomplete_type_inform): Early return if
	TYPE_MAIN_DECL is null.

/testsuite
2014-05-22  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/61088
	* g++.dg/cpp0x/lambda/lambda-ice13.C: New.
	* g++.dg/cpp0x/lambda/lambda-ice7.C: Adjust.

From-SVN: r210829
parent aa87aced
2014-05-22 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/61088
* lambda.c (add_capture): Enforce that capture by value requires
complete type.
* typeck2.c (cxx_incomplete_type_inform): Early return if
TYPE_MAIN_DECL is null.
2014-05-21 Jonathan Wakely <jwakely@redhat.com> 2014-05-21 Jonathan Wakely <jwakely@redhat.com>
PR c/61271 PR c/61271
......
...@@ -453,6 +453,9 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p, ...@@ -453,6 +453,9 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
initializer = build_x_compound_expr_from_list (initializer, ELK_INIT, initializer = build_x_compound_expr_from_list (initializer, ELK_INIT,
tf_warning_or_error); tf_warning_or_error);
type = TREE_TYPE (initializer); type = TREE_TYPE (initializer);
if (type == error_mark_node)
return error_mark_node;
if (array_of_runtime_bound_p (type)) if (array_of_runtime_bound_p (type))
{ {
vla = true; vla = true;
...@@ -489,8 +492,16 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p, ...@@ -489,8 +492,16 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
error ("cannot capture %qE by reference", initializer); error ("cannot capture %qE by reference", initializer);
} }
else else
/* Capture by copy requires a complete type. */ {
type = complete_type (type); /* Capture by copy requires a complete type. */
type = complete_type (type);
if (!dependent_type_p (type) && !COMPLETE_TYPE_P (type))
{
error ("capture by copy of incomplete type %qT", type);
cxx_incomplete_type_inform (type);
return error_mark_node;
}
}
} }
/* Add __ to the beginning of the field name so that user code /* Add __ to the beginning of the field name so that user code
......
...@@ -434,6 +434,9 @@ abstract_virtuals_error (abstract_class_use use, tree type) ...@@ -434,6 +434,9 @@ abstract_virtuals_error (abstract_class_use use, tree type)
void void
cxx_incomplete_type_inform (const_tree type) cxx_incomplete_type_inform (const_tree type)
{ {
if (!TYPE_MAIN_DECL (type))
return;
location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)); location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
tree ptype = strip_top_quals (CONST_CAST_TREE (type)); tree ptype = strip_top_quals (CONST_CAST_TREE (type));
......
2014-05-22 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/61088
* g++.dg/cpp0x/lambda/lambda-ice13.C: New.
* g++.dg/cpp0x/lambda/lambda-ice7.C: Adjust.
2014-05-22 Xinliang David Li <davidxl@google.com> 2014-05-22 Xinliang David Li <davidxl@google.com>
* g++.dg/ipa/devirt-15.C: Fix expected message. * g++.dg/ipa/devirt-15.C: Fix expected message.
......
// PR c++/61088
// { dg-do compile { target c++11 } }
void f()
{
typedef void (*X) ();
X x[] = { [x](){} }; // { dg-error "incomplete type" }
}
void g()
{
typedef void (X) ();
X x[] = { [x](){} }; // { dg-error "array of functions|not declared" }
}
...@@ -5,5 +5,5 @@ struct A; // { dg-message "forward declaration" } ...@@ -5,5 +5,5 @@ struct A; // { dg-message "forward declaration" }
void foo(A& a) void foo(A& a)
{ {
[=](){a;}; // { dg-error "invalid use of incomplete type" } [=](){a;}; // { dg-error "incomplete type" }
} }
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