diff mbox

Fix PR c++/21113

Message ID 1396538682-31474-1-git-send-email-patrick@parcs.ath.cx
State New
Headers show

Commit Message

Patrick Palka April 3, 2014, 3:24 p.m. UTC
Hi,

This patch fixes c++/21113 which reports that the C++ frontend does not
forbid jumps into the scope of identifiers with variably-modified types.

The patch simply augments decl_jump_unsafe() to disallow jumping into
blocks that initialize variably-modified decls.

I bootstrapped and regtested this change on x86_64-unknown-linux-gnu.

2014-04-03  Patrick Palka  <patrick@parcs.ath.cx>

	PR c++/21113
	* decl.c (decl_jump_unsafe): Consider variably-modified decls.
---
 gcc/cp/decl.c                    |  5 ++---
 gcc/testsuite/g++.dg/ext/vla14.C | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/vla14.C

Comments

Jason Merrill April 4, 2014, 9:03 p.m. UTC | #1
Applied, thanks.

Jason
diff mbox

Patch

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 5bd33c5..6571af5 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2785,9 +2785,8 @@  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)))
diff --git a/gcc/testsuite/g++.dg/ext/vla14.C b/gcc/testsuite/g++.dg/ext/vla14.C
new file mode 100644
index 0000000..278cb63
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/vla14.C
@@ -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" }
+    ;
+  }
+}