By the standard https://eel.is/c++draft/basic.start#dynamic-1, implicitly
instantiated global variable's initializer has no order. However GCC has
the *intuitive behavior* for the two test cases in https://clang.godbolt.org/z/MPdhYTqhK.
The underlying problem is basically wg21.link/cwg362 which has no concensus yet.
I wish both cases could work, like GCC. However, to make the original cwg362 test case work,
I needs an extra data structure to track the instantiation order for implicitly
instantiated global variable. So the current patch only work for the first test case.
Will the reviewers be supportive if I make the original cwg362 test case work too?
@rsmith , if inline global variable initialization has ordering requirements, we have a bug, because I believe this GVA_DiscardableODR codepath handles them, and we come through here to give them separate initializers in llvm.global_ctors. See the example with two separate global_ctors entries on godbolt:
https://gcc.godbolt.org/z/5d577snqb
As long as LLVM doesn't provide ordering guarantees about same priority initializers in global_ctors, inline globals have the same problems as template instantiations. IMO whatever solution we use to order inline globals should be used for template instantiations.
Intuitively, that means LLVM should promise to run global_ctors in left-to-right order, and if all TUs instantiate initializers in the same order, everything should behave intuitively.
The question then becomes, why doesn't this work already?