From 56beadfee10c25cf7d01877898f84754247a28f6 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Sat, 1 May 2004 19:57:28 +0000 Subject: [PATCH] backport: re PR c++/14724 (Destructor not called on backwards goto past initialization) Backport from gcc-3_4-branch: 2004-03-30 Mark Mitchell PR c++/14724 * decl.c (start_decl_1): Do not decide whether or not to create a new cleanup level until after the type has been completed. From-SVN: r81394 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/decl.c | 10 ++++++++-- gcc/testsuite/g++.dg/init/goto1.C | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 02082405ab29..abc8892cf406 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2004-05-01 Gabriel Dos Reis + + Backport from gcc-3_4-branch: + 2004-03-30 Mark Mitchell + PR c++/14724 + * decl.c (start_decl_1): Do not decide whether or not to create a + new cleanup level until after the type has been completed. + 2004-04-01 Richard Henderson PR c++/14804 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 91ef96afb9ee..e17254ef4f3d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7872,8 +7872,6 @@ start_decl_1 (decl) if (type == error_mark_node) return; - maybe_push_cleanup_level (type); - if (initialized) /* Is it valid for this decl to have an initializer at all? If not, set INITIALIZED to zero, which will indirectly @@ -7929,6 +7927,14 @@ start_decl_1 (decl) if (! initialized) DECL_INITIAL (decl) = NULL_TREE; + + /* Create a new scope to hold this declaration if necessary. + Whether or not a new scope is necessary cannot be determined + until after the type has been completed; if the type is a + specialization of a class template it is not until after + instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR + will be set correctly. */ + maybe_push_cleanup_level (type); } /* Handle initialization of references. DECL, TYPE, and INIT have the diff --git a/gcc/testsuite/g++.dg/init/goto1.C b/gcc/testsuite/g++.dg/init/goto1.C index b0a0c5253b64..c086efd54288 100644 --- a/gcc/testsuite/g++.dg/init/goto1.C +++ b/gcc/testsuite/g++.dg/init/goto1.C @@ -12,12 +12,12 @@ struct C { int main(int, char **) { { int i = 0; - again: + again: C v; if (++i < 10) goto again; } - + return j; } -- 2.47.2