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

    <tr>
        <th>Summary</th>
        <td>
            clang-format: Indenting of #else in nested #if/#elif/#else
        </td>
    </tr>

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

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

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

<pre>
    Two potential issues when formatting the first sample below with clang-format:
- The code in the #else and #elif is formatted even when it is not the active choice where as code in `#if 0` is not formatted. Is it expected that the inactive parts of #if/#elif/#else and #if/#else are formatted or not?
- The indent level in the second #else is wrong.

Using clang-format version 15.0.7.

**First Sample**
Formatting:
```c
int myFunction(int x) {
#if 1
#if 1
while(x != 0) {
#else
while (x == 0) {
#endif
#if 0
int y;
return y;
#elif
int x;
return x;
#else
int z;
return z;
#endif
}
}
```
Gives me:
```c
int myFunction(int x) {
#if 1
#if 1
    while (x != 0) {
#else
    while (x == 0) {
#endif
#if 0
int y;
return y;
#elif 1
        int x;
 return x;
#else
    int z;
    return z;
#endif
 }
#endif
}
```
**Second Sample**
Adding an #elif in the first nested #if makes the indent in the #else in second nested #if correct:
```c
int myFunction(int x) {
#if 1
#if 1
while (x != 0) {
#elif 0
while (x > 0) {
#else
while (x == 0) {
#endif
#if 0
int y;
return y;
#elif 1
int x;
return x;
#else
int z;
return z;
#endif
}
#endif
}
```
Gives:
```c
int myFunction(int x) {
#if 1
#if 1
    while (x != 0) {
#elif 0
 while (x > 0) {
#else
    while (x == 0) {
#endif
#if 0
int y;
return y;
#elif 1
        int x;
        return x;
#else
        int z;
        return z;
#endif
 }
#endif
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVs2SozYQfhpx6RqXLGyDDxxmyyG15908gBBt0EZILknYnn36lJAx4EziPWSyS1E2iK9_9LW-rubOyUYjFmT7iWwPCe99a2yhvvW6aY3qksrUb8XXi4GT8ai95Aqkcz06uLSo4Whsx72XugHfIhyldR4c704KoUJlLnCRvgWhuG5eIpikr4QeCH19ga8tgjA1gtSDOWEpKofAdR2f5RGkG4NgDXhGHQNLH75o4wdDLrw8I4jWSIEBYBG4u_smO0pYKo9AyY6OdnevK_jsgj-8nlCEKL7l0a3UN8cnbr0Dc4TBDWHlLbvxacp5uWZxlryxIS5Jy_n2pa5Re1B4RjXS4FCYkQGHId-LNbpZRbv4-4cLnM95hTNaJ42G9XZFV9kCTVi4y6E6X4bqxJX4tbwX8V6bwNhwi_gutYfurey18NJowvKwcCVsDyT7NMYIDK_febm0MgTMr0DYmqQHoI-GYZ8zLERwengfrGt5nIehU45vJL0BLfre6tnCWLI79vqIvS6xY0oB-_0R-32BnWWUHR4fRirj6-_yjA46_BiqAQDmFD7l-9HgQzifZxeuJfvw7_SPBhPjYeVJGWCi_x_Ks6xKlMOXKLy_K-S1roPcuJ7akp41PI0uCDwy0_E_0d3ax6Dth-Ym9SjwhZkw1qLwH6jAZ0diquriQPz2U-U67uB_EOwPHZRBvj9ZuxOH8OOV-hWEfrue6_19zf-nuk_qIq336Z4nWKx3-Waf7miWJ20hdvuU15sqrXmVoag2GcVM5DWtcppnYpPIglGW0i3brNNNts1X2RZrwbKM03W1y-st2VDsuFQrpc7dytgmGUamYsf26yxRvELlhoGLMY2XOE8RxsL8ZYtg81L1jSMbqqTzbvLipVdYPMxS8HnoMqE9xflkbDLz7vLexJL0VhWt96fhOIflspG-7auVMB1hZQh7-3s5WfMtNCdWxuGPsHLYzF8BAAD__4N52Jc">