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

    <tr>
        <th>Summary</th>
        <td>
            clang-format misformats designated initializers mixed with preprocessor blocks
        </td>
    </tr>

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

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

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

<pre>
    Clang-format file:
```
BasedOnStyle: Chromium
Standard: Cpp11
```

Example 1, where the #else block is surprisingly indented:
```c++
int main() {
  SOME_MACRO((SomeStruct {
               .some_long_field_name = 1,
#if defined(SOME_FLAG)
               .to_prevent_multiple_inits_on_one_line = 2,
               .is_this_indented_weirdly_2 = 3,
#else
                 .yet_another_long_field_name = 3,
#endif
               .the_final_initializer_whee = 4,
             }),
             second_macro_arg);
}
```

Example 2, where a comment in the #if block causes the next line to be surprisingly indented:
```c++
int main() {
  SOME_MACRO((SomeStruct {
               .some_long_field_name = 1,
#if defined(SOME_FLAG)
               // Some useful comment here.
                   .to_prevent_multiple_inits_on_one_line = 2,
#else
                 .yet_another_long_field_name = 3,
#endif
               .the_final_initializer_whee = 4,
             }),
             second_macro_arg);
}
```
Example 3, where reversing the order of the comment and the designated initializer results in the comment being lined up with... something:
```c++
int main() {
  SOME_MACRO((SomeStruct {
               .some_long_field_name = 1,
#if defined(SOME_FLAG)
               .to_prevent_multiple_inits_on_one_line = 2,
    // Some useful comment here.
#else
                   // Another useful comment here.
                 .yet_another_long_field_name = 3,
#endif
               .the_final_initializer_whee = 4,
             }),
             second_macro_arg);
}

```

Example 4, where a comment in the #else block is also indented in a surprising way:
```c++
int main() {
  SOME_MACRO((SomeStruct {
               .some_long_field_name = 1,
#if defined(SOME_FLAG)
               // Some useful comment here.
                   .to_prevent_multiple_inits_on_one_line = 2,
#else
                   // Another useful comment here.
                 .yet_another_long_field_name = 3,
#endif
               .the_final_initializer_whee = 4,
             }),
             second_macro_arg);
}
```

In all of these examples, I would have expected the designated initializers to be lined up.

In examples 2 and 4, I would have expected the comments to be lined up with the designated initializer on the next line.

In example 3, I can kind of understand the weird indent of the `//` comment, since it could be read as applying to the `#else`, though generally speaking, the alignment is still a bit wonky.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlV11v4jgU_TXJizUROBDgIQ8MnY4qzajS8gMiJ75JvHXsyHZKmV-_1w5paRc6u_O03UERxF_nXh8fH5tS82O-k0w1n2ptOuZILSRE6Taa3USzbZTNTk8ofmYW-L3au2PoQ3at0Z0YurF175jizPDQ0vfz-UWM8fvLE-t6CWQe0R05tGCAuBZIRFOQFkgpdfVAhCV2ML0RVqhGHolQHJQD_vf0qoh-9k-oFcqRjgkV0XVENyRaneoJ2d9__1J83-7-uA9t673uYO_MULnzXq8-icU-hdSqKWoBkheKdZhnehNSP6VBU1ETDrVQmBzC-jC337ZfMfxlUKeL3sAjzqboBukEUlEIJZwttMIHAyJUiEKfo7zFELZwLX5NrBQHEIbLY0HDwPQ8PU_qRRTEOYIrmNJIv7k4z9dAiov6ypxawKGKyTATwaT4gYi4tiPM4vJEotWNZ-lim4VKK150rDK6YKbxHdPTMvlxP5cXfZEXI5XuOmQKZTRpDVdtVFrFBgs2VCt4ciTQ7zQp4X-qwIje4kN8eIJTrwf5TI9nK7kill-U7m-lwEl76Yv2PF_GSygoTBsOhug6FCbW0TpDmYMVjWKoMXI2CUSwSLadtDuNKsGDesY5GXpyEK5NkoR4xaA3qObD6_SXnfKfCfx9YT6jbEdx_pud8uFF_XNzXbxvrq8PciatfrZP34udOSs5sOOHl-p_yVJ_a-Ve0uwdCk7Kk-miLmHUsPUSviMHPUhOWvboG3qovESvm7E93Qwm203eBJqwCQ2uvng_xmlJ3oIGL3_vRNDq9XXlShbjMXSHNxxFHnD_eQoG3IbGuunICffG096cjiVPX1AQvkwpeiDcrRUQ4bDOT6f0ZxvjhOEG73t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