calling destructors without calling constructors! for static object
Igor Durdanovic
igord@research.nj.nec.com
Fri Dec 10 14:59:00 GMT 1999
The following code demonstrates what I would call a bug.
It calls global destructor for C although C was never constructed!
Igor
-------------------------
#include <iostream>
struct A
{
A() { cout << __PRETTY_FUNCTION__ << endl; }
~A() { cout << __PRETTY_FUNCTION__ << endl; }
};
struct B
{
B() { cout << __PRETTY_FUNCTION__ << endl; exit(0); }
~B() { cout << __PRETTY_FUNCTION__ << endl; }
};
struct C
{
C() { cout << __PRETTY_FUNCTION__ << endl; }
~C() { cout << __PRETTY_FUNCTION__ << endl; }
};
A a;
B b;
C c;
int main()
{
return 0;
}
-------------------------
g++ -v
Reading specs from /usr/local/gcc-2.95.2/lib/gcc-lib/i486-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
g++ -o bug bug.C
bug
A::A()
B::B()
C::~C() <- what ????????
B::~B()
A::~A()
More information about the Gcc-bugs
mailing list