Previously, Itanium ABI guard variables were set after initialization was complete for non-block declared variables with static and thread storage duration. That resulted in initialization of such variables being restarted in cases where the variable was referenced while it was still under construction. Per C++20 [class.cdtor]p2, such references are permitted (though the value obtained by such an access is unspecified). The late initialization resulted in recursive reinitialization loops for cases like this:
template<typename T> struct ct { struct mc { mc() { ct<T>::smf(); } void mf() const {} }; thread_local static mc tlsdm; static void smf() { tlsdm.mf(); } }; template<typename T> thread_local typename ct<T>::mc ct<T>::tlsdm; int main() { ct<int>::smf(); }
With this change, guard variables are set before initialization is started so as to avoid such reinitialization loops.