<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101897>101897</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] spurious “misleading indentation” warning
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zamfofex
</td>
</tr>
</table>
<pre>
I commonly write code that looks like this:
~~~ C
for (y = 0 ; y < width ; y++)
for (x = 0 ; x < width ; x++)
{
/* ... */
/* ... */
/* ... */
}
for (y = 0 ; y < width ; y++)
for (x = 0 ; x < width ; x++)
arr[y][x] = 0;
~~~
But Clang seems to dislike it, adding a spurious “misleading indentation” warning on the very next line:
~~~ C
for (y = 0 ; y < width ; y++)
for (x = 0 ; x < width ; x++)
arr[y][x] = 0;
printf("hey\n"); /* warning here! */
~~~
This seems like a bug to me. (Specially because of the suspiscious placement of the warning.) From what I can tell, it sees the indendation of the nested `for (x = 0 ; ...)` loop, and then thinks anything indented on the same level is “misleading” because it thinks “it looks like it’s inside” the outer `for (y = 0 ; ...)` loop. (Without realising that the outer loop is itself on that same indentation level!)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVM-OozgTf5riUhoEJjThwKFJvkhz_lbas4Ei1LaxI9t0hz30s6_shOl0a1ZazWFXioitcpX9-1MlneOzJmqgbKE8JnLxk7HNn3IezUjXpDPD2nzH3syz0WrFN8uesDcDoZ-kR2XMi0PFL2HPDopnyI6Q3b_v7-94uC1HYxHEfkUojpghFC2G9QHfePDTbQ-ijb_6U8r1IeX6JeX6JQWq9rZARBAnEM-YpimCeA67X45AdXyE9e9gQURpLZTtCuURyvYK5fGWDkX7g9_Hd7WLx4OS-oyOaHboDQ7sojjsQRxQDgPrM0p0l8WyWRzC_wTsM6gPMztFMoZZD6S99Gz0Fj7im7Q6BI1GPxG-kl1R09WjYk1fZP-PxP8HhN2-F8vajyD2IMREK5QHDUKEOkW7WWDDO5ElEPknO3yh_beJ3Z3xyLXEbjkH8mcKNtr__0I9S6VW7KiXiyM0YyTRLe7Cro9CXJTsaSbtt-D9ASmIGk_WzPgW-u079lKjJ6WCnuzDvS6ej6oNUbWthCbnaUB4yn7CZpqG0vCUhR6-RHfoIaQFgVm_OJR6DavNEDRs4js5Eyp6JYX8Uwt92GZDzH6r-uM4f5oe7LdA7ZC144E-qoRLzeLJPmBZ_xZLJP139pNZPFqSil1AEefVR6VwMjyfvSM13qBJf8P20AE3nCByEHUyNMVQF7VMqMkrIao634kqmZqxp0521GWV7PYjCcrGp74odiXJfpS0T7gRmdhl-2yXV3kmqnQs5diJfqRdPozyqYRdRrNklSr1OqfGnhN2bqEmz_J9XSVKdqRcHNJC9KHFg2HLY2KbkPCtW84Odpli591HCc9exckeh0Lohl_u-2Sxqpm8v8QRH1rkdGY_LV3amxnEKdx5__t2seYP6j2IU8TgQJzuMF4b8VcAAAD__9994rM">