Global variables in C++11 with non-trivial constructors are constructed before the entry to main during a static initialization phase.
Likewise non-function-local thread_local variables are constructed during a per-thread “thread_local initialization phase”.
Does the C++11 standard specify in what order these variables shall be constructed? In both cases if there are two variables:
// global scope
A::A() { b.f(); } // A constructor uses global b
A a;
B b;
Does the C++11 standard specify in what order they shall be initialized, or that an error should be produced if a variable is used uninitialized?
Likewise for non-function-local thread_local:
// global scope
A::A() { b.f(); } // A constructor uses global b
thread_local A a;
thread_local B b;
Does the standard specify the order they must be constructed, and does it define what will happen if the variable is used from the constructor of another before it is initialized?
Can you please provide a C++11 standard reference in support of any claims you make to have an answer.
Your statement that “Global variables in C++11 with non-trivial constructors are constructed before the entry to main during a static initialization phase.” doesn’t seem to be entirely true – they may not be initialised until the dynamic initialization phase
For variables with “ordered initialization”, which your first a and b are, then the standard says
3.6.2/2 covers all this.
Edit: as far as I can tell your second a and b don’t have ordered initialization, and could be initialized in either order. But I may be missing something.