<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/146036>146036</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format rejects formatting with -length=0
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kadircet
</td>
</tr>
</table>
<pre>
starting with 1fae5918b3d6fbed8ce6d8a2edf31bdf304ca8db we reject `-length=0`. despite the behavior not being specified for such "point" ranges, formatting library and its users (clang-format, clangd, clang-tidy, ...) accepted those, and there are also some unittests that rely on this.
In the wild there are also some editor integrations, most notably VSCode, that can request for formatting of ranges with `0` length (e.g. after user deleted some code, or for empty lines).
Expected behavior in such a scenario is hard to define, the most obvious is to not format anything, but that isn't the existing behavior (I am not sure if that's incidental or deliberate), but clang-format tool erroring-out in such cases now is resulting in regressions for those workflows. Moreover it's also creating divergence with rest of the applications, leaking the details of the specific formatter being used into the higher level applications.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVM1u4zgMfhrlQsSw5ebHBx-6MxtgDntaYO-yRNvcKpJXpJPJ2y8kp50WmEPRGCI_fj-UDDNNAbFXhz_U4fvOrDLH1L8ZR8mi7IboHj2LSUJhgjvJDM1o8NA156F1x3FAd7Z4dGej0Y1tM7ixrV-sObsB7ggJ_0UroI713mOYZFbt91od6woc8kKCIDPCgLO5UUwQosCAeRIvaGkkdDDGBLzaGZTWS6QgSmtIJkzISn_Lx1cjhZ2nIZn0ABMckDCsjIlB6bP1Jkz7rTL3lG_38Wsv5B75q6oqpTsw1uIi6EDmyJgPMqLMmBBM_vMcgeMVYQ0kgiwMMhuBhP4BMYDMxJWqX1X9-iMUhXfyv0dARxITUBCckhGKoai6Rpbshhn8A_75-1t0hUeZYk2AhP-tyFLM-eRAHJ_ObEmpY53Nhs367ARWUwVmFEzFHXDoMSstXOxzyoYJeF3kAZ5CNrp76vnz54I2d3xkRmGLxwBbDCZRBGKYTXIgERyOFJ7ccZMVhxvFlXOVxBL5pgBMeMhMYcrVwyqbWuKg9ElKO_4kLjo_hit9_gHmWlB4TQg0ljalTwwULDkMYnyW5NDTgMkIKt29j_i8GSAxesCUYqIw7eMqH9qsYWQI8Z5JJ-TVFxqUg5gSMufcimllZeAe09vo450r-CsmjDdMQBupEr1NaAqCoxumCYPFLbGUQ41jUWuWxZP9tRMezVvuyWcOxZDn99LnbbHvu4DpeY1WRpeXK5aymaYZE3i8of8CX-1c37qu7cwO--Z0aOq6O7XNbu7bru1eutHV3cGaoztgMw7NyY3j-dDa5lTvqNe1PtRHfapP7aGtqxrdcDqaRrvauvPZqZcar4Z85f3tWsU07Yh5xb55OdbtcefNgJ7L86P114uq84OU-ty3H9aJ1UvtiYV_IQmJx_5LiNuLw59vRXH20_uzW5PvZ5GFVfuq9EXpy0Qyr0Nl41XpS4Z__tsvKWY8pS-FNSt9eRK_9fr_AAAA__9nNM6c">