Skip to content

Commit

Permalink
[clang-format] Continue after non-scope-closers in getLengthToMatchin…
Browse files Browse the repository at this point in the history
…gParen

Summary:
This fixes a regression introduced by `r331857` where we stop the search for
the End token as soon as we hit a non-scope-closer, which prematurely stops before
semicolons for example, which should otherwise be considered as part of the unbreakable tail.

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D46824

llvm-svn: 332225
  • Loading branch information
krasimirgg committed May 14, 2018
1 parent 796fb99 commit 964293e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ static unsigned getLengthToMatchingParen(const FormatToken &Tok,
return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr;
};
for (; End->Next; End = End->Next) {
if (End->Next->CanBreakBefore || !End->Next->closesScope())
if (End->Next->CanBreakBefore)
break;
if (!End->Next->closesScope())
continue;
if (End->Next->MatchingParen->isOneOf(tok::l_brace,
TT_ArrayInitializerLSquare,
tok::less)) {
Expand Down
12 changes: 12 additions & 0 deletions clang/unittests/Format/FormatTestObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,18 @@ TEST_F(FormatTestObjC, ObjCArrayLiterals) {
" @\"aaaaaaaaaaaaaaaaaaaaaaaaaa\"\n"
"];\n");
}

TEST_F(FormatTestObjC, BreaksCallStatementWhereSemiJustOverTheLimit) {
Style.ColumnLimit = 60;
// If the statement starting with 'a = ...' is put on a single line, the ';'
// is at line 61.
verifyFormat("int f(int a) {\n"
" a = [self aaaaaaaaaa:bbbbbbbbb\n"
" ccccccccc:dddddddd\n"
" ee:fddd];\n"
"}");
}

} // end namespace
} // end namespace format
} // end namespace clang

0 comments on commit 964293e

Please sign in to comment.