summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-22 22:28:24 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-22 22:28:24 +0000
commit5444a0b4a92e29508d8ebc7dc2e67e3de50b6775 (patch)
tree482d94f82159646fb44fea3724778df67a2b8f71
parent1343c5e0ac057323f4231512641fa81c5f225c15 (diff)
downloadgcc-5444a0b4a92e29508d8ebc7dc2e67e3de50b6775.tar.gz
/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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210829 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/lambda.c15
-rw-r--r--gcc/cp/typeck2.c3
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C14
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C2
6 files changed, 45 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2021e2df26e..a594e9393f3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+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>
PR c/61271
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index bb6014b23d0..e72682c9487 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -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,
tf_warning_or_error);
type = TREE_TYPE (initializer);
+ if (type == error_mark_node)
+ return error_mark_node;
+
if (array_of_runtime_bound_p (type))
{
vla = true;
@@ -489,8 +492,16 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
error ("cannot capture %qE by reference", initializer);
}
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
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index e98942d7d2a..18bc25f766d 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -434,6 +434,9 @@ abstract_virtuals_error (abstract_class_use use, tree type)
void
cxx_incomplete_type_inform (const_tree type)
{
+ if (!TYPE_MAIN_DECL (type))
+ return;
+
location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type));
tree ptype = strip_top_quals (CONST_CAST_TREE (type));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4e86b8dd633..a799992e502 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+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>
* g++.dg/ipa/devirt-15.C: Fix expected message.
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C
new file mode 100644
index 00000000000..4c611ad8ee1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C
@@ -0,0 +1,14 @@
+// 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" }
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C
index 1d7dfcc933e..6f8272aeb60 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C
@@ -5,5 +5,5 @@ struct A; // { dg-message "forward declaration" }
void foo(A& a)
{
- [=](){a;}; // { dg-error "invalid use of incomplete type" }
+ [=](){a;}; // { dg-error "incomplete type" }
}