re PR c++/21113 (Jumps into VLA or VM scope not rejected for C++)
authorPatrick Palka <patrick@parcs.ath.cx>
Fri, 4 Apr 2014 19:35:54 +0000 (02:35 +0700)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 4 Apr 2014 19:35:54 +0000 (15:35 -0400)
PR c++/21113
* decl.c (decl_jump_unsafe): Consider variably-modified decls.

From-SVN: r209124

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/ext/vla14.C [new file with mode: 0644]

index e095569..615db3f 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-04  Patrick Palka  <patrick@parcs.ath.cx>
+
+       PR c++/21113
+       * decl.c (decl_jump_unsafe): Consider variably-modified decls.
+
 2014-04-04  Fabien ChĂȘne  <fabien@gcc.gnu.org>
 
        * class.c (find_abi_tags_r): Check for the return of warning
index f1743dd..0d8ebcb 100644 (file)
@@ -2785,12 +2785,11 @@ decl_jump_unsafe (tree decl)
       || type == error_mark_node)
     return 0;
 
-  type = strip_array_types (type);
-
-  if (DECL_NONTRIVIALLY_INITIALIZED_P (decl))
+  if (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
+      || variably_modified_type_p (type, NULL_TREE))
     return 2;
 
-  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
+  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
     return 1;
 
   return 0;
diff --git a/gcc/testsuite/g++.dg/ext/vla14.C b/gcc/testsuite/g++.dg/ext/vla14.C
new file mode 100644 (file)
index 0000000..278cb63
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/21113
+// { dg-options "" }
+
+void
+f (int n)
+{
+  goto label; // { dg-error "from here" }
+  int a[n]; // { dg-error "crosses initialization" }
+label: // { dg-error "jump to label" }
+  ;
+}
+
+void
+g (int n)
+{
+  switch (1)
+  {
+  case 1:
+    int (*a)[n]; // { dg-error "crosses initialization" }
+  default: // { dg-error "jump to case label" }
+    ;
+  }
+}