Commit 745d26d9 by Mark Mitchell Committed by Mark Mitchell

re PR c++/17976 (Calls the dtor twice)

	PR c++/17976
	* decl.c (cp_finish_decl): Do not call expand_static_init more
	than once for a single variable.

	PR c++/17976
	* g++.dg/init/dtor3.C: New test.

From-SVN: r89081
parent 53e782e5
2004-10-14 Mark Mitchell <mark@codesourcery.com>
PR c++/17976
* decl.c (cp_finish_decl): Do not call expand_static_init more
than once for a single variable.
2004-10-14 Matt Austern <austern@apple.com> 2004-10-14 Matt Austern <austern@apple.com>
* Make-lang.in (pt.o): depends on pointer-set.h * Make-lang.in (pt.o): depends on pointer-set.h
......
...@@ -4763,6 +4763,7 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags) ...@@ -4763,6 +4763,7 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
tree cleanup; tree cleanup;
const char *asmspec = NULL; const char *asmspec = NULL;
int was_readonly = 0; int was_readonly = 0;
bool var_definition_p = false;
if (decl == error_mark_node) if (decl == error_mark_node)
return; return;
...@@ -4904,6 +4905,11 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags) ...@@ -4904,6 +4905,11 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
/* Remember that the initialization for this variable has /* Remember that the initialization for this variable has
taken place. */ taken place. */
DECL_INITIALIZED_P (decl) = 1; DECL_INITIALIZED_P (decl) = 1;
/* This declaration is the definition of this variable,
unless we are initializing a static data member within
the class specifier. */
if (!DECL_EXTERNAL (decl))
var_definition_p = true;
/* The variable is being defined, so determine its /* The variable is being defined, so determine its
visibility. */ visibility. */
determine_visibility (decl); determine_visibility (decl);
...@@ -4970,7 +4976,15 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags) ...@@ -4970,7 +4976,15 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
initialize_local_var (decl, init); initialize_local_var (decl, init);
} }
if (TREE_STATIC (decl)) /* If a variable is defined, and then a subsequent
definintion with external linkage is encountered, we will
get here twice for the same variable. We want to avoid
calling expand_static_init more than once. For variables
that are not static data members, we can call
expand_static_init only when we actually process the
initializer. It is not legal to redeclare a static data
member, so this issue does not arise in that case. */
if (var_definition_p && TREE_STATIC (decl))
expand_static_init (decl, init); expand_static_init (decl, init);
} }
} }
......
2004-10-14 Mark Mitchell <mark@codesourcery.com>
PR c++/17976
* g++.dg/init/dtor3.C: New test.
2004-10-15 Ben Elliston <bje@au.ibm.com> 2004-10-15 Ben Elliston <bje@au.ibm.com>
* gcc.dg/ppc-stackalign-1.c: Set dg-options to {}. * gcc.dg/ppc-stackalign-1.c: Set dg-options to {}.
......
// PR c++/17976
// { dg-do run }
extern "C" void abort();
struct A
{
static int i;
A(){}
~A(){i++;if(i>1)abort();}
};
int A::i = 0;
A a;
extern A a;
int main()
{
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment