What does the standard have to say about function-local static initialization during program exit?
EDIT: For clarity, I mean a case as in the code example - the local static b
is constructed after another static a
is constructed(so supposedly b
should be destroyed before a
), but b
is also constructed during a
's destructor, so should it be destroyed immediately? after? UB?
I didn't manage to find any reference to this matter.
I'd like to know if such a case is UB, or should it have some defined behaviour?
The following code is an example of that:
struct B{};
void foo()
{
static B b;
}
struct A
{
~A() { foo(); }
};
int main()
{
static A a;
return 0;
}
As you can see, the destructor of A would occur during program exit(since it has static storage), and it'll try to construct a B static instance.
I'm more interested in C++17 if it makes any difference in this subject.