]> granicus.if.org Git - clang/commitdiff
[clang-format] fix PR38525 - Extraneous continuation indent spaces with BreakBeforeBi...
authorJonas Toth <jonas.toth@gmail.com>
Fri, 24 Aug 2018 17:14:31 +0000 (17:14 +0000)
committerJonas Toth <jonas.toth@gmail.com>
Fri, 24 Aug 2018 17:14:31 +0000 (17:14 +0000)
Summary: See bug report https://bugs.llvm.org/show_bug.cgi?id=38525 for more details.

Reviewers: djasper, klimek, krasimir, sammccall

Reviewed By: sammccall

Subscribers: hiraditya, JonasToth, cfe-commits

Tags: #clang

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

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

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

index 0c202565051d593450819c0d41f05a1c1e2f00de..f035aa71e5a4783499a12d5f5483a46308131e73 100644 (file)
@@ -700,7 +700,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
     // Indent relative to the RHS of the expression unless this is a simple
     // assignment without binary expression on the RHS. Also indent relative to
     // unary operators and the colons of constructor initializers.
-    State.Stack.back().LastSpace = State.Column;
+    if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None)
+      State.Stack.back().LastSpace = State.Column;
   } else if (Previous.is(TT_InheritanceColon)) {
     State.Stack.back().Indent = State.Column;
     State.Stack.back().LastSpace = State.Column;
index 2e780e163bec71558efceb7eac3e8f810ea61adb..d73b1d82671854ac9ae14e62525056c70b9acc49 100644 (file)
@@ -3375,6 +3375,18 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) {
                "    = bbbbbbbbbbbbbbbbb\n"
                "      >> aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa);",
                Style);
+
+  Style.ColumnLimit = 80;
+  Style.IndentWidth = 4;
+  Style.TabWidth = 4;
+  Style.UseTab = FormatStyle::UT_Always;
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+  Style.AlignOperands = false;
+  EXPECT_EQ("return someVeryVeryLongConditionThatBarelyFitsOnALine\n"
+            "\t&& (someOtherLongishConditionPart1\n"
+            "\t\t|| someOtherEvenLongerNestedConditionPart2);",
+            format("return someVeryVeryLongConditionThatBarelyFitsOnALine && (someOtherLongishConditionPart1 || someOtherEvenLongerNestedConditionPart2);",
+                   Style));
 }
 
 TEST_F(FormatTest, EnforcedOperatorWraps) {