From: Mark Mitchell Date: Tue, 30 Mar 2004 23:45:00 +0000 (+0000) Subject: re PR c++/14724 (Destructor not called on backwards goto past initialization) X-Git-Tag: releases/gcc-4.0.0~9106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c6671cbbbc4bccc110b26c24a3eb706f596b7960;p=thirdparty%2Fgcc.git re PR c++/14724 (Destructor not called on backwards goto past initialization) 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. PR c++/14763 * pt.c (tsubst_default_argument): Clear current_function_decl. PR c++/14724 * g++.dg/init/goto1.C: New test. PR c++/14763 * g++.dg/template/defarg4.C: New test. From-SVN: r80101 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6e3f71a19501..6fba6057b3f7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +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. + + PR c++/14763 + * pt.c (tsubst_default_argument): Clear current_function_decl. + 2004-03-30 Zack Weinberg * name-lookup.c, parser.c: Use new shorter form of GTY markers. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 0b802ff7578f..ce530fa47093 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3788,8 +3788,6 @@ start_decl_1 (tree 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 @@ -3845,6 +3843,14 @@ start_decl_1 (tree 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/cp/pt.c b/gcc/cp/pt.c index 3e3d0e91f5d1..b096017430e6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5902,6 +5902,10 @@ tsubst_default_argument (tree fn, tree type, tree arg) /* FN is already the desired FUNCTION_DECL. */ push_access_scope (fn); + /* The default argument expression should not be considered to be + within the scope of FN. Since push_access_scope sets + current_function_decl, we must explicitly clear it here. */ + current_function_decl = NULL_TREE; arg = tsubst_expr (arg, DECL_TI_ARGS (fn), tf_error | tf_warning, NULL_TREE); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6bba3d51dc91..416128f53c81 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2004-03-30 Mark Mitchell + + PR c++/14724 + * g++.dg/init/goto1.C: New test. + + PR c++/14763 + * g++.dg/template/defarg4.C: New test. + 2004-03-30 Hartmut Penner * gcc.dg/altivec-11.c: Extend test for more valid cases. diff --git a/gcc/testsuite/g++.dg/init/goto1.C b/gcc/testsuite/g++.dg/init/goto1.C new file mode 100644 index 000000000000..b0a0c5253b64 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/goto1.C @@ -0,0 +1,23 @@ +// PR c++/14724 +// { dg-do run } + +int j; + +template +struct C { + C() { ++j; } + ~C() { --j; } +}; + +int main(int, char **) { + { + int i = 0; + again: + C v; + if (++i < 10) + goto again; + } + + return j; +} + diff --git a/gcc/testsuite/g++.dg/template/defarg4.C b/gcc/testsuite/g++.dg/template/defarg4.C new file mode 100644 index 000000000000..293538adbd15 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/defarg4.C @@ -0,0 +1,14 @@ +// PR c++/14763 + +struct A { + int get() const {} + static A *foo(); +}; + +template struct S { + S(unsigned int = A::foo()->get()) ; +}; + +void foo() throw() { + S f; +}