In C++ with -Werror=comment, multiline comments are not allowed.
clang-format could accidentally introduce multiline comments when reflowing.
This adapts clang-format to not introduce multiline comments by not allowing a
break after \. Note that this does not apply to comment lines that already are
multiline comments, such as comments in macros.
Details
- Reviewers
sammccall - Commits
- rG7b7170fa5791: [clang-format] avoid introducing multiline comments
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
One concern about looping, otherwise just style nits.
clang/lib/Format/BreakableToken.cpp | ||
---|---|---|
105–119 | Can you add a high-level comment to this loop? I guess the idea is "Some spaces are unacceptable to break on, rewind past them." | |
106 | The warning is worth mentioning, but fundamentally we have the warning because such code is confusing, and we shouldn't produce confusing code. maybe: // If a line-comment ends with `\`, the next line continues the comment, // whether or not it starts with `//`. This is confusing and triggers -Wcomment. // Avoid introducing multiline comments by not allowing a break after '\'. | |
110 | Do we really want to predicate this on isCpp()? // comments are allowed by C99. | |
131–134 | doesn't this mean that we won't loop? if Text ends with "blah \ \" then you'll split between "blah" and the first "\"? I guess this could be structured: while () { if (special case 1) { // adjust pos continue; } if (special case 2) { // adjust pos continue; } break; } (This is equivalent to the old if/elseif/break which is too hard to add complex conditions to) |
Still LG
clang/lib/Format/BreakableToken.cpp | ||
---|---|---|
110 | Sigh, I guess I forgot what isCpp() means again... :) |
The warning is worth mentioning, but fundamentally we have the warning because such code is confusing, and we shouldn't produce confusing code.
maybe: