<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55804>55804</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Static initialization order of variables in a single TU
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tchatow
      </td>
    </tr>
</table>

<pre>
    I left a question on stack overflow detailing the issue: https://stackoverflow.com/questions/72286507/static-initialization-order-of-inline-variables-in-single-tu, but no answers yet. I'm not sure whether it is a Clang bug or if there is no guarantee about this initialization order.

The example is:

```#include <cstdio>

struct TestValue;

inline const TestValue* v_ptr = nullptr;

struct TestValue {
    static const TestValue v1;

    TestValue() {
        v_ptr = this;
        printf("TestValue Initialized at %p\n", this);
    }
};

struct CallTest {
    CallTest() {
        printf("CallTest Initalized at %p\n", this);
        printf("v_ptr = %p\n", v_ptr);
    }
};

const inline TestValue TestValue::v1{};
const inline CallTest ct{};



int main() {}```

Surprisingly, `ct` is initialized before `v1`

Using Clang 14.0.3, but this issue goes back further. Is this a bug or are there no guarantees about this initialization order?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVMGOmzAQ_RpzGQUREwIcOOwmXWnPu9trZcAEtw5O7SHp9us7hpCQdKtqkZVYnpk3b549U5r6vXgGLRsEAT976VCZDmg5FNUPMEdpG21OUEsUSqtuB9hKUM71ksUP0CIeHG0Yf6I1xEwhYWX2dDZhOtqnnGfrJEpHV1TVQnUKldDqt_A-C2NraRemoXPKJRdHYZUotXR0sHCUXcsF9oxvoOwROgOicydpHbxLDOGZ8XRPpwiutxJOrSSuFhQSX6puowXRL_sdGDpsfCHWl-Jxdr2wokMpQZSGoLGl81tyMJALWbRl0cP4-0pSyF9if9Aex8swM7J1dF48Vl2l-1oCizeVw1oZFn-Z-zq0fYXwSlJ9FdpL-zg3j2pARSrOnfgDHL8d0BLsFrpea9rfRd4DA0vPdqBvvIR7XDgu71C87yxtxnh-C-S_KxUv3gVhMh-s6rAZgvk11fMksaxBIDCeHFiy6cjHX_IAxPMbLJZuz9Ro82GxG6G1z3BLcTr9F_05vwuCp_cpdvdIV1HuggfDJ2ob7-j8EK76zV7MAy26OaprFnwTdimrwju3v3-pBNgL1c3kIv_Lk555vvSWKh6a891XRmbCX0cw7yASsJSNoX4jC7G8hXjz0ef-XK7CKIynFh_70E8b2BnpoPRDqemt711qeDc6iKmrBSUY23re0-5_Tc3ip6Au4jqPcxGgQi2Ll7E1PvIG08BlMJEHpR9HE7y-Bb3Vxe1Q3Cls-_I8DbU-Tn-LgzXfJUnFn4YC_YBMkixaBW2xbMrlalVmjeDJKpdllq8ykaZZkjTVOq6bQItSalew5JHeUydP54lMbyvZBqrgEefROlpGhBKlYZ4lUbVuYl7nfNlUS7aKJF2uDj2P0NhdYIuBEsnoyKiVQ3c1CufUrpNySEf4osfW2AKrVqA5BUPqYqD-B5Dn8Sc">