4
struct A
{
    A() : n(1)
    {}

    int n;
};

struct B
{
    B() : n(2)
    {}

    int n;
};

thread_local A a;
B b;

int main()
{
    return a.n;
}

a is defined before b.

My question:

Does the C++ standard guarantee B::B() is called before A::A() is called?

xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • Not 100% sure because of `thread_local` so related/dupe: http://stackoverflow.com/questions/3746238/c-global-initialization-order-ignores-dependencies/3746249#3746249 – NathanOliver Feb 15 '17 at 15:44
  • http://en.cppreference.com/w/cpp/language/initialization –  Feb 15 '17 at 15:46

0 Answers0