<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68823>68823</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy: 'readability-misleading-indentation' confused by "if (...) LABEL: {...}" depending on linebreaks
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
joelkp
</td>
</tr>
</table>
<pre>
I've had some false positives from `clang-tidy` when using `readability-misleading-indentation`. It's confused by one specific C idiom where a label is added between an `if` and its `{`, also depending on the use of linebreaks. Below is a file that does it, tested with `clang-tidy` 16.0.6.
```
int main() {
goto LABEL;
// ...
if (0)
LABEL: {
// contents here don't matter
}
return 0;
}
```
The check in `clang-tidy` seems to view the indentation on the `return 0;` line as being one level deeper than it actually is.
```
clang-tidy tidythis.c -checks='readability-misleading-indentation'
...
1 warning generated.
/home/joel/swproj/misc/tidythis.c:8:2: warning: misleading indentation: statement is indented too deeply [readability-misleading-indentation]
return 0;
^
/home/joel/swproj/misc/tidythis.c:3:2: note: did you mean this line to be inside this 'if'
if (0)
^
```
Note that removing the linebreak after `if (0)` in this example, joining the two lines, will remove the false positive. As will the moving of `LABEL:` to just after `{`, instead of before it. And fully removing the use of a label also removes the warning.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVdGO6jgM_ZrwYlGVFFr60AfmzkW60tU-7Q-kjUs9kyaodmH5-1VaGGBGuztahFKwG_vExz4xzHTwiJXavKjN68KM0oWhegvo3o-LOthL9Uvp4oTQGQsceoTWOEY4BiahEzK0Q-hB5WnjjD8shexF5SmcO_QwMvlD9A1orKnJkVyWPbFDY8kfluQtejFCwas8TeCXKF0wNMG3I6OF-gLBI_ARG2qpgR9AlkIfgw8IBpyp0QExGGvj6yhnRA_Gx5zURhzGWyDhaFDFS1z1DzCOA1g8oo8wIHiQDmFkhNCCI4_1gOadE3hBF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