Cleaning up the myth in other answers: no, cleanup order has nothing to do with a stack.
The C++ standard does not even define the concept of a stack except in two circumstances:
- stack unwinding (as a process).
- the stack container adapter.
Neither is relevant here. What is relevant though is section 6.6:
On exit from a scope (however accomplished), objects with automatic
storage duration that have been constructed in that scope are
destroyed in the reverse order of their construction.
Transfer out of a loop, out of a block, or back past an initialized
variable with automatic storage duration involves the destruction of
objects with automatic storage duration that are in scope at the point
transferred from but not at the point transferred to.
The fact most architectures implement this behavior using an execution stack is a “happy coincidence”, but it is not mandated by the standard.
On the other hand reverse order destruction is guaranteed, regardless of whether the implementation will use a stack or not.