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: unassignedclangb...@nondot.org
Reporter: geoffrey.carl...@activision.com
CC: djas...@google.com, kli...@google.com,
llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs