diff options
author | Mark Mitchell <mark@codesourcery.com> | 2003-02-26 05:39:01 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2003-02-26 05:39:01 +0000 |
commit | cec24319c61d616dc10f918187a72a9622180821 (patch) | |
tree | c5c90ab38ff9bf5549a387a267d1e8f572227552 /gcc/cp/decl2.c | |
parent | 38a843911d49becd4f01c6b8badebe19fb25682a (diff) | |
download | gcc-cec24319c61d616dc10f918187a72a9622180821.zip gcc-cec24319c61d616dc10f918187a72a9622180821.tar.gz gcc-cec24319c61d616dc10f918187a72a9622180821.tar.bz2 |
re PR c++/9683 (bug in initialization chains for static const variables from template classes)
PR c++/9683
* decl2.c (prune_vars_needing_no_initialization): Do not throw
away initializations for DECL_EXTERNAL VAR_DECLs.
(finish_file): Adjust accordingly.
* pt.c (instantiate_decl): Do not defer VAR_DECLs.
PR c++/9683
* g++.dg/template/static3.C: New test.
From-SVN: r63455
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r-- | gcc/cp/decl2.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index ae17403..52170da 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -84,7 +84,7 @@ static void finish_static_initialization_or_destruction (tree); static void generate_ctor_or_dtor_function (bool, int); static int generate_ctor_and_dtor_functions_for_priority (splay_tree_node, void *); -static tree prune_vars_needing_no_initialization (tree); +static tree prune_vars_needing_no_initialization (tree *); static void write_out_vars (tree); static void import_export_class (tree); static tree get_guard_bits (tree); @@ -2400,21 +2400,23 @@ do_static_destruction (tree decl) i.e., the first variable should be initialized first. */ static tree -prune_vars_needing_no_initialization (tree vars) +prune_vars_needing_no_initialization (tree *vars) { - tree var; - tree result; + tree *var = vars; + tree result = NULL_TREE; - for (var = vars, result = NULL_TREE; - var; - var = TREE_CHAIN (var)) + while (*var) { - tree decl = TREE_VALUE (var); - tree init = TREE_PURPOSE (var); + tree t = *var; + tree decl = TREE_VALUE (t); + tree init = TREE_PURPOSE (t); /* Deal gracefully with error. */ if (decl == error_mark_node) - continue; + { + var = &TREE_CHAIN (t); + continue; + } /* The only things that can be initialized are variables. */ my_friendly_assert (TREE_CODE (decl) == VAR_DECL, 19990420); @@ -2422,17 +2424,25 @@ prune_vars_needing_no_initialization (tree vars) /* If this object is not defined, we don't need to do anything here. */ if (DECL_EXTERNAL (decl)) - continue; + { + var = &TREE_CHAIN (t); + continue; + } /* Also, if the initializer already contains errors, we can bail out now. */ if (init && TREE_CODE (init) == TREE_LIST && value_member (error_mark_node, init)) - continue; + { + var = &TREE_CHAIN (t); + continue; + } /* This variable is going to need initialization and/or finalization, so we add it to the list. */ - result = tree_cons (init, decl, result); + *var = TREE_CHAIN (t); + TREE_CHAIN (t) = result; + result = t; } return result; @@ -2625,8 +2635,7 @@ finish_file () aggregates added during the initialization of these will be initialized in the correct order when we next come around the loop. */ - vars = prune_vars_needing_no_initialization (static_aggregates); - static_aggregates = NULL_TREE; + vars = prune_vars_needing_no_initialization (&static_aggregates); if (vars) { |