The following code is not possible to compile. I'm wondering why:
#include <string>
constinit std::string constinit_string; // WORKS
constinit thread_local int my_int; // WORKS
constinit thread_local std::string const_init_thread_local; // DOESN'T WORK
// ERROR BY GCC
//error: 'constinit' variable 'const_init_thread_local' does not have a constant initializer
// ERROR BY CLANG
//error: variable does not have a constant initializer
Also, MSVC doesn't allow constinit thread_local std::vector, though Clang and GCC do.
I know that in MSVC neither std::string nor std::vector are allowed to be "constinit" at all in Debug mode because I believe they make debug-related allocations, still in Release mode MSVC doesn't allow constinit thread_local for both std::string and std::vector. And Clang and GCC both disallow constinit thread_local for std::string.
constinit_stringtwice, with different storage classifiers? At least that's what the error message is saying. Have you tried to change the name of one of the variables?constinit_string(with thethread_local) does not compile even if you comment out the first (as you can try in the Godbolt link).std::stringdoesn't zero-fill itself fully, making the default constructor non-constant (similar to this situation). The compiler is being lenient in case of global initialization since that automatically zero-fills everything, but is being stricter in case of thread_local initialization.