<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57258>57258</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy readability-else-after-return fix generates invalid code with LF files on Windows
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sean-mcmanus
</td>
</tr>
</table>
<pre>
Use a test.cpp file with LF line endings on Windows (it doesn't repro with CLRF line endings). I used clang-tidy 14.0.0.
clang-tidy.exe --checks=readability-else-after-return --fix test.cpp
```cpp
void func(int ii) {
if (ii == 0) {
return;
}
else {//dfd
//aaa
}//dfd
}
```
Bug: Output is invalid code
```cpp
void func(int ii) {
if (ii == 0) {
return;
}
/dfd
//aaa
//dfd
}
```
Seems like an off-by-one error with code that is expecting CLRF line endings. The bug also repros with output from the --export-fixes yaml file.
The LF line endings on Windows is not "normal" but can occur when bypassing git's normal conversion to CLRF or when a user opt for that.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVE2PmzAQ_TVwGYEICSEcOOw2WqnSSpX6oZ4HPIC7xka2yW7-fcewzSZaadWeChZgez7eG7-hMeJc_3AECJ6cT9tpgk4qgmfpB3h8ACU1AWkhde_AaPgptTDPDqL8ID0IQ05HeenB0mTN6vXp8eutX5RXKXyG2ZGAVqHuEy_FGTa7NOM7yo5Rdrc-33ZTeiFIknag9slF26MlFNhIJf05IeUowc6TTSz52Wo27OTLhcFrxH22jsvKyUgB3azbAF57kJKRQVTer9vAl-wWZhI4JQ_I3lmEa80aba-Wo_L4NgkAF6_8gYfoxK37uoyIt-63xpeAFx7Xhbqf-2h7B19mP81MxIHUJ1RMrzWCrg3_YxX-jvo_0f5GNDrW1hMLVoPpuqQ5JyYozVpjV_mFCoAfcCkLvUzUehbhe1Wm8H0gaOYeUDmzCtitIcxa1s6akSMFHXIcY31QGTk446iWLrnRboj2QcMwGG080821sSMq_uDkHtpApG1nRj-QhuY8oXMBcC89d1bwCuZMS5_IOskhvVnZmFcfDK1lwUwMmdcC91dkMdWb_T6riqrabWJRb0W1rTD20iuqr1rx4-4KvdWTJovcYTdKu_wmQjWu6cazVfXg_cS9e7ceMfMZ5iZtzcgTpU5_XgnX_RcfEk-lczPx7-KhKPPiEA91XgrR7Ld7UYiqqlrEA-5QUIeU5ZXI21hhw3jrqLgPhaVnWELwd1QcY1nnWZ5nhzzLNrtit0m7zWGL-W5TiuaAVJXRLqMRpUoDjtTYPrb1AolV4XhTSefd22Y4mF4TLek4Ps5-MLZ2hDoZ2xH17OIlf73g_w3cXp9n">