Generally it is said that the destructors of static objects are called in the reverse order of the constructors. As I understand, constinit objects are initialized at compile time, so their destructors should be called after the destructors of "normal" static objects.
The program
struct A
{
constexpr A(const char* t): t_(t) {}
~A() {std::cout << "~A(" << t_ << ")\n";}
const char* t_;
};
static A a1("static");
int main () {
static constinit A a2("constinit");
return 0;
}
(using GCC 10), however, gives the output
~A(constinit)
~A(static)
i.e. the constinit object is destroyed before the "normal" static object (although it was constructed earlier). Is the "reverse order" rule no longer valid for constinit objects?