This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Wrong destruction order of static objects in g++
- To: egcs-bugs at cygnus dot com
- Subject: Wrong destruction order of static objects in g++
- From: Klaus-Georg Adams <Klaus-Georg dot Adams at chemie dot uni-karlsruhe dot de>
- Date: Thu, 4 Jun 1998 14:57:32 +0200
- Cc: jkanze at otelo dot ibmmail dot com
Hi,
James Kanze (jkanze@otelo.ibmmail.com) has given me a nice test case
which shows that egcs (and gcc-2.7.2) get the destruction order of
static objects wrong. The attached program is supposed to print
0
1
2
3
3
2
1
0
according to the CD2 [basic.start.term], but prints
0
1
2
3
1
3
2
0
Is there a way in the old-deja framework to compare the output of a
program to a default?
-- kga
-------------------------------------------------------------------------
Klaus-Georg Adams Email: Klaus-Georg.Adams@chemie.uni-karlsruhe.de
Institut f. Anorg. Chemie, Lehrstuhl II Tel: 49(0)721 608 3485
Universität Karlsruhe, D-76128 Karlsruhe
-------------------------------------------------------------------------
#include <iostream>
class A {
public:
A();
~A();
private:
int myCnt;
};
class B {
public:
B();
~B();
private:
int myCnt;
};
static int cnt;
static A a1;
static B b1;
static A a2;
void
f()
{
static A a;
}
A::A() :
myCnt( cnt ++ )
{
std::cout << myCnt << std::endl;
}
A::~A()
{
std::cout << myCnt << std::endl;
}
B::B() :
myCnt( cnt +1 )
{
f();
std::cout << myCnt << std::endl;
++cnt;
}
B::~B()
{
std::cout << myCnt << std::endl;
}
int
main()
{
return 0;
}