Parapura said:
class A
{
};
class B
{
~B()
{
static A a;
}
};
static B b;
Is this undefined behavior. or the standard seems to handle this case
as well ?
I think it's unspecified.
The Standard (as I read it) says that the destruction of 'a' will
happen before B::~B returns (since it was constructed after 'b',
it has to be destroyed completely before 'b' is), however, it is known
that calling d-tors for static objects is done by registering them
with 'atexit' (although it is not explicitly specified by the Standard),
and the Standard does not specify what happens if you [try to] register
a function with 'atexit' while another function previously registered
with 'atexit' is executed during the program termination.
You might want to ask about it in comp.std.c++, refer to 3.6.3, 18.3,
6.7.
I say, try to avoid situations like that if possible.
V