]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/61088 (segfault with array of lambdas initialized with initializer list...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 22 May 2014 22:28:24 +0000 (22:28 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 22 May 2014 22:28:24 +0000 (22:28 +0000)
/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

gcc/cp/ChangeLog
gcc/cp/lambda.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice7.C

index 2021e2df26e8bd79b250a2feeb6899c37ed3c4ec..a594e9393f3dc3ad6051bfcc89243999978c3add 100644 (file)
@@ -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
index bb6014b23d04d10338e7d0a6fd151d5fae774695..e72682c9487c5fadc8f92dfe14bf08b621cc6666 100644 (file)
@@ -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
index e98942d7d2a56b77abf1eb92459c6e0ef463fbf0..18bc25f766da65cd769c1618d1346d51890514dd 100644 (file)
@@ -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));
 
index 4e86b8dd6339c7e72d8fff552418824bc2845f63..a799992e502aa7210d4a0a18757d1af78bc331c2 100644 (file)
@@ -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 (file)
index 0000000..4c611ad
--- /dev/null
@@ -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" }
+}
index 1d7dfcc933ea5c93bc762c25d1a973f4817aa085..6f8272aeb605b9b209a52c3a231a3527f02a0b1e 100644 (file)
@@ -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" }
 }