]> granicus.if.org Git - clang/commitdiff
clang-format: Fix indentation corner case.
authorDaniel Jasper <djasper@google.com>
Wed, 18 Dec 2013 10:44:36 +0000 (10:44 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 18 Dec 2013 10:44:36 +0000 (10:44 +0000)
Before:
  aaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                 .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  aaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                   .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();

After:
  aaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                 .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  aaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
                   .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();

Probably still not ideal, but should be a step into the right direction.

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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index e8dc8d4a7f11cf606020d5aa62328b983f870ed9..c840c4557f556f31f981eda5905191d1ca3b8529 100644 (file)
@@ -546,6 +546,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
     //       ParameterToInnerFunction));
     if (*I > prec::Unknown)
       NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
+    NewParenState.StartOfFunctionCall = State.Column;
 
     // Always indent conditional expressions. Never indent expression where
     // the 'operator' is ',', ';' or an assignment (i.e. *I <=
@@ -573,7 +574,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
       if (Current.MatchingParen && Current.BlockKind == BK_Block) {
         // If this is an l_brace starting a nested block, we pretend (wrt. to
         // indentation) that we already consumed the corresponding r_brace.
-        // Thus, we remove all ParenStates caused bake fake parentheses that end
+        // Thus, we remove all ParenStates caused by fake parentheses that end
         // at the r_brace. The net effect of this is that we don't indent
         // relative to the l_brace, if the nested block is the last parameter of
         // a function. For example, this formats:
index 436a1f6d52b31d286c83117499e2e216ae176cbf..7d58ec2ed963815ac827d3151769f519faf38336 100644 (file)
@@ -3922,6 +3922,12 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {
   verifyFormat(
       "aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
       "    aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa));");
+  verifyFormat("aaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+               "                 .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();");
+  verifyFormat("aaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "               aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+               "               .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa());");
 }
 
 TEST_F(FormatTest, WrapsTemplateDeclarations) {