PR c++/85256 - ICE capturing pointer to VLA.
authorJason Merrill <jason@redhat.com>
Mon, 9 Apr 2018 15:32:05 +0000 (11:32 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 9 Apr 2018 15:32:05 +0000 (11:32 -0400)
* lambda.c (add_capture): Distinguish between variable-size and
variably-modified types.

From-SVN: r259240

gcc/cp/ChangeLog
gcc/cp/lambda.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla2.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/vla7.C
gcc/testsuite/g++.dg/cpp1y/vla9.C

index ba323bf7c20e9e4179489d817840cc5b9b994418..c3751551517684b1a9141192977f9ca2246df750 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-09  Jason Merrill  <jason@redhat.com>
+
+       PR c++/85256 - ICE capturing pointer to VLA.
+       * lambda.c (add_capture): Distinguish between variable-size and
+       variably-modified types.
+
 2018-04-06  Jason Merrill  <jason@redhat.com>
 
        PR c++/85214 - ICE with alias, generic lambda, constexpr if.
index 374060626c15f3efd6d76b175b6568da6f3fe434..e9b962a8f3316cab44bf676f349e3371e49c775e 100644 (file)
@@ -554,13 +554,13 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
   else if (!dependent_type_p (type)
           && variably_modified_type_p (type, NULL_TREE))
     {
-      error ("capture of variable-size type %qT that is not an N3639 array "
+      sorry ("capture of variably-modified type %qT that is not an N3639 array "
             "of runtime bound", type);
       if (TREE_CODE (type) == ARRAY_TYPE
          && variably_modified_type_p (TREE_TYPE (type), NULL_TREE))
        inform (input_location, "because the array element type %qT has "
                "variable size", TREE_TYPE (type));
-      type = error_mark_node;
+      return error_mark_node;
     }
   else
     {
index d4de131fc230190ffba28b4a5a14e64f06322b38..aee9694852d2d4f291ed11e525c38c76e94c856a 100644 (file)
@@ -7,6 +7,6 @@ void f() {
   int m = 1;
   int d[n][m];
   [&]() {
-    return d[1];               // { dg-error "variabl" }
+    return d[1];               // { dg-prune-output "sorry" }
   }();
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-vla3.C
new file mode 100644 (file)
index 0000000..eebdbcd
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/85256
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Wno-vla }
+
+void foo(int i)
+{
+  int (*x)[i];
+  [=]{ [=]{ 0 ? x : x; }; };   // { dg-bogus "sorry" "" { xfail *-*-* } }
+
+}
index df34c8219dbe317b4698b08247b6fab4d4be440d..afa5fac508d1839c3da42d2439eadc34dcc8a0f6 100644 (file)
@@ -6,7 +6,7 @@ int main(int argc, char** argv)
 {
   int x[1][argc];
 
-  [&x](int i) {                        // { dg-error "variable.size" }
-    x[0][i] = 0;               // { dg-prune-output "assignment" }
+  [&x](int i) {                        // { dg-prune-output "sorry" }
+    x[0][i] = 0;               // { dg-prune-output "not captured" }
   }(5);
 }
index 939de30a3c1765e6e35ec3d26b681eb4d101e707..2c5b3a5404e9665d630694a3f9080adcb362c581 100644 (file)
@@ -25,7 +25,7 @@ int main(){
     fa[0][1]=1.8;
     auto fx=[&](){
         for(int c=0; c<2; c++){
-            printf("use me", fa[0][c]);        // { dg-error "capture of variable-size type" }
+            printf("use me", fa[0][c]);        // { dg-prune-output "sorry" }
         }
     };
     call(fx);