forked from OSchip/llvm-project
[clang-format] Update removed brace's next token's WhitespaceRange
Fixes #57803. Differential Revision: https://reviews.llvm.org/D134146
This commit is contained in:
parent
eaa7b324d5
commit
7349084e7a
|
@ -1920,10 +1920,13 @@ private:
|
||||||
assert(Next || Token == Line->Last);
|
assert(Next || Token == Line->Last);
|
||||||
if (!Next && NextLine)
|
if (!Next && NextLine)
|
||||||
Next = NextLine->First;
|
Next = NextLine->First;
|
||||||
const auto Start =
|
SourceLocation Start;
|
||||||
Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)
|
if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
|
||||||
? Token->Tok.getLocation()
|
Start = Token->Tok.getLocation();
|
||||||
: Token->WhitespaceRange.getBegin();
|
Next->WhitespaceRange = Token->WhitespaceRange;
|
||||||
|
} else {
|
||||||
|
Start = Token->WhitespaceRange.getBegin();
|
||||||
|
}
|
||||||
const auto Range =
|
const auto Range =
|
||||||
CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
|
CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
|
||||||
cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
|
cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
|
||||||
|
|
|
@ -26006,6 +26006,17 @@ TEST_F(FormatTest, RemoveBraces) {
|
||||||
"}",
|
"}",
|
||||||
Style);
|
Style);
|
||||||
|
|
||||||
|
verifyFormat("while (0)\n"
|
||||||
|
" if (a)\n"
|
||||||
|
" return b;\n"
|
||||||
|
"return a;",
|
||||||
|
"while (0) {\n"
|
||||||
|
" if (a) {\n"
|
||||||
|
" return b;\n"
|
||||||
|
"}}\n"
|
||||||
|
"return a;",
|
||||||
|
Style);
|
||||||
|
|
||||||
Style.ColumnLimit = 65;
|
Style.ColumnLimit = 65;
|
||||||
verifyFormat("if (condition) {\n"
|
verifyFormat("if (condition) {\n"
|
||||||
" ff(Indices,\n"
|
" ff(Indices,\n"
|
||||||
|
|
Loading…
Reference in New Issue