So I gave this program to g++ and clang (both on Linux, x86_64):
#include
using namespace std;
template
struct A {
sta
Your code is incorrect. The important part of the standard is 6.6.3/1 [basic.start.dynamic] in N4659:
Dynamic initialization of a non-local variable with static storage duration is unordered if the variable is an implicitly or explicitly instantiated specialization [...]
Because the initialization is not ordered, you cannot rely on the order of destruction. Any order is legal, regardless of order of construction. See 6.6.4/3 [basic.start.term]
gcc is thus allowed to destroy s
before it destroys a
,
which is what happens and causes the weird output. Live.