From 822cc906fd9341dd64f808f4553aaa07c8de8c6a Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Sat, 5 Apr 2014 02:35:54 +0700 Subject: [PATCH] re PR c++/21113 (Jumps into VLA or VM scope not rejected for C++) PR c++/21113 * decl.c (decl_jump_unsafe): Consider variably-modified decls. From-SVN: r209124 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 7 +++---- gcc/testsuite/g++.dg/ext/vla14.C | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/vla14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e0955691e50..615db3fa3e4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2014-04-04 Patrick Palka + + PR c++/21113 + * decl.c (decl_jump_unsafe): Consider variably-modified decls. + 2014-04-04 Fabien ChĂȘne * class.c (find_abi_tags_r): Check for the return of warning diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f1743dd74dc..0d8ebcb7bfc 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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 index 00000000000..278cb63b938 --- /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" } + ; + } +} -- 2.11.4.GIT