Issue |
143657
|
Summary |
[clang-format] Apply different ColumnLimit for comments
|
Labels |
clang-format
|
Assignees |
|
Reporter |
M-Fabian
|
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;
}
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs