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 ba323bf..c375155 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 3740606..e9b962a 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 d4de131..aee9694 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 df34c82..afa5fac 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 939de30..2c5b3a5 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);