]> granicus.if.org Git - clang/commitdiff
[clang-format] Continue after non-scope-closers in getLengthToMatchingParen
authorKrasimir Georgiev <krasimir@google.com>
Mon, 14 May 2018 10:33:40 +0000 (10:33 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Mon, 14 May 2018 10:33:40 +0000 (10:33 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332225 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestObjC.cpp

index 82e5f6e5197bc85aabd5f09cdf1c9ecfba6cca58..1d04ad0a49999b3f90719d81a117cd93a97ba075 100644 (file)
@@ -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)) {
index c6246fd502540b4a8738d7eff2a4f3f936b601dc..459e522308ac61281c071e66e54f6649b79db7d5 100644 (file)
@@ -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