<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143657>143657</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Apply different ColumnLimit for comments
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
M-Fabian
</td>
</tr>
</table>
<pre>
We are using clang-format for some time now and enjoy the auto-formatting for the most part.
One issue we have is with commented out code. If a line is slightly shorter than the column limit, then by commenting it out, it becomes 3 characters longer due to "// ", thus exceeding the column limit. clang-format then reformats the comment, thereby breaking the code snippet. Commenting it back in results in a syntax error.
The solution seems to be straightforward: Allow comment lines to have a ColumnLimit + 3 before adding a line break.
Consider the following example for illustration:
// original code with a 80 character line
void f()
{
cout << "This is a looooooooooooooooong line which I need to comment out.\n";
int k = 5;
}
// comment code out, line becomes 83 characters wide and is adjusted.
void f()
{
// cout << "This is a looooooooooooooooong line which I need to comment
// out.\n"; int k = 5;
}
// comment code back in, resulting in syntax errors
void f()
{
cout << "This is a looooooooooooooooong line which I need to comment
out.\n "; int k = 5;
}
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VU1v6zYQ_DXUZRFBpj5iH3RwbBh4QIteHtAzJa4kJhRpkKs4_vfF0nIT59ICLZ4upujd2Z3ZIaViNKNDbEX9IupjphaafGh_fzqpziiXdV5f2z8RVEBYonEj9Fa58WnwYVYEgw8Q_YxAZkZw_gLKaUD36q9AE4JayK-xxMkcz_uzjwRnFSgXxV4U-z8cgolxQbggTOqd3-BiaILezzM6Qg1-Iei9xhx-DKDAmpQD0ZpxInuFOPlAyPjKpSK9t8vswJrZkJAH3nPQXe-Q3I8hhuU_DUGHvZ8xQgn9pILqCUME692IAfSCQB6ElEKehDzdVoy5RMCPHlEz3vey-aNcqYOAt7e4Rqdm1v4CdlfoAqq3TzSNEJ05n5FyODy03qn-DQwjxsVS5KWCeHWkPgBD8GFV9-eEEL1dyHgHEXGOzKVDiBQUqzf4cFFBi3IPe2v95d5VEjkFp5koOCRuvzE1EPIFSuiYDYLSif86lsRgLX7wLhqNt7kPnuE5Ej_UfLaYHGGsXbgV7k-U-1seAMCqtQ9mNE7ZmxjJFgq2xeeYUtU1590bDYOQWyF3d5jnl3UF0LONRHkQ5YFn-HMykV2kwPrvjxtvbC6T6Sf4AQ5RsxZ3cfxCuagPjq1QpgrGEbyBKI9Qrzup-vG-emB1h0mkVhfe1Ft9uH0w4sVoTKeLu9WvSyTU-b_jvBb8P8l_x37U4j8IsXqaxbjZOnndPdg6_upR_w15f-504Z_5Zrot9a7cqQzbzXO1a6RsNlU2tc_dpih2XVkN3aZsallINey2xU4VVTPITmamlYWsi2azKZpNU1f5bpDbquGwWkksB1EVOCtjc2vf59yHMUt3aLupyqZ-zqzq0MZ0s0v59R7iputjFlrOe-qWMYqqsCZS_EQiQzZ9FR4S6yPsz2d7BW2GAQNP7euVwId5lSxmS7DtRHSOfKTTpEdD09LlvZ-FPHGl9efpHPwr9iTkKRGIQp5WDu-t_CsAAP__pNogZw">