Consider a situation like this:
#include <iostream>
int foo() {
static struct S {
int value;
S(int a): value(a) {}~S() {
std::cout << "End is nigh";
}
}
s(42);
return s.value;
}
int main() {
return foo();
}
In implementations of compilers, I researched these results in code that sets S::~S() up with the call of _atexit, i.e. local static object would cease to exist at some point after the exit of main().
What happens if a destructor of an object in global static/extern scope calls a function that has a function-local static scope which, by definition, gets constructed the first time execution enters this scope and the call from the destructor is that first time? This also might be a case with a destructor of object function-local static scope constructs another object in function-local static scope.
This might be a case with a codebase that relies on multiple instances of Scott Meyers's implementation of singletons, where the object instance is a function-local static variable. I'm not sure what guaranteed to happen if such singleton has to access standard streams on this stage of execution, is it determined when they cease to function after atexit handlers.