[llvm-bugs] [Bug 46964] New: Trailing comments after endif adds macro continuation
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Aug 3 03:20:30 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46964
Bug ID: 46964
Summary: Trailing comments after endif adds macro continuation
Product: clang
Version: 10.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: Formatter
Assignee: unassignedclangbugs at nondot.org
Reporter: geoffrey.carlton at activision.com
CC: djasper at google.com, klimek at google.com,
llvm-bugs at lists.llvm.org
Created attachment 23809
--> https://bugs.llvm.org/attachment.cgi?id=23809&action=edit
Input to be formatted with llvm and ColumnLimit 0
When an #endif or #else has a trailing comment, and a comment follows on the
next line, clang-format can add an inappropriate macro continuation '\\' at the
end of the first comment.
Minimum repro is attached. Input file is attached, but is in full:
"#if A()\n#endif // #if A()\n\t\t\t// hello\n"
Output becomes:
"#if A()\n#endif // #if A() \\\n // hello\n"
Reproduces in clang 10.0.0 with -style="{BasedOnStyle: llvm, ColumnLimit: 0}".
Also reproduces in latest code built from github.
The code is related to ContinuationIndenter::addTokenOnNewLine where it is
adding whitespace with ContinuePPDirective set. That causes the comment to be
joined with the macro continuation character.
A partial workaround is before that call to replaceWhitespace:
if (State.Line->First->is(tok::hash) && Current.is(tok::comment) &&
State.Line->First->Next != nullptr) {
if (isIfdefType(State.Line->First->Next)) {
// Don't count this trailing comment part of a PP directive or it will
// unnecessarily escape the end with '\' If we happen to have a another
// comment on the next line.
ContinuePPDirective = false;
// An additional problem is later parts of clang-format can shift
around
// the following comment, causing the output not to be stable.
Current.Finalized = true;
}
}
Where isIfdefType is checking for ifdef/elif/else/endif. That's good enough
for a quick fix but isn't the real solution to the problem.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200803/410682d3/attachment.html>
More information about the llvm-bugs
mailing list