This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: p2736.C Is dtor order guaranteed?


> Would such use of atexit be within its (POSIX?) specification?
> For example, on HP-UX 10.20 the manual entry for atexit says:
> 
>       An atexit() call during exit processing is always unsuccessful.
> 
> If a function with local static object is called the first time from the
> destructor of another static (function or not) object, the mechanism
> wouldn't work (on HP, at least).

Even if I can't find exact wording for that, I'd expect this case to
have undefined behaviour in C++, as well (i.e. construction of an
object with static storage duration after exit has been called).

> Would that object (have to be) constructed and destroyed again or is that
> undefined behaviour?

That is undefined as per 3.6.3/2:

# If a function contains a local object of static storage duration
# that has been destroyed and the function is called during the
# destruction of an object with static storage duration, the program
# has undefined behavior if the flow of control passes through the
# definition of the previously destroyed local object.

> Do gcc's destructors set the "initialised" flag to false on
> destruction so that it is constructed (and destroyed if atexit
> works) again?

I don't think it does.

Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]