r240129 - clang-format: Make exception to AlwaysBreakBeforeMultilineStrings more

Daniel Jasper djasper at google.com
Fri Jun 19 03:32:29 PDT 2015


Author: djasper
Date: Fri Jun 19 05:32:28 2015
New Revision: 240129

URL: http://llvm.org/viewvc/llvm-project?rev=240129&view=rev
Log:
clang-format: Make exception to AlwaysBreakBeforeMultilineStrings more
conservative.

In particular, this fixes an unwanted corner case.

Before:
  string s =
      someFunction("aaaa"
                   "bbbb");

After:
  string s = someFunction(
      "aaaa"
      "bbbb");

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=240129&r1=240128&r2=240129&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Jun 19 05:32:28 2015
@@ -170,7 +170,7 @@ bool ContinuationIndenter::mustBreak(con
 
   if (Style.AlwaysBreakBeforeMultilineStrings &&
       (NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
-       Previous.is(tok::comma)) &&
+       Previous.is(tok::comma) || Current.NestingLevel < 2) &&
       !Previous.isOneOf(tok::kw_return, tok::lessless, tok::at) &&
       !Previous.isOneOf(TT_InlineASMColon, TT_ConditionalExpr) &&
       nextIsMultilineString(State))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=240129&r1=240128&r2=240129&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jun 19 05:32:28 2015
@@ -4662,6 +4662,10 @@ TEST_F(FormatTest, AlwaysBreakBeforeMult
   verifyFormat("aaaaa(aaaaaa, aaaaaaa(\"aaaa\"\n"
                "                      \"bbbb\"));",
                Break);
+  verifyFormat("string s = someFunction(\n"
+               "    \"abc\"\n"
+               "    \"abc\");",
+               Break);
 
   // As we break before unary operators, breaking right after them is bad.
   verifyFormat("string foo = abc ? \"x\"\n"





More information about the cfe-commits mailing list