]> granicus.if.org Git - clang/commitdiff
clang-format: Make exception to AlwaysBreakBeforeMultilineStrings more
authorDaniel Jasper <djasper@google.com>
Fri, 19 Jun 2015 10:32:28 +0000 (10:32 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 19 Jun 2015 10:32:28 +0000 (10:32 +0000)
conservative.

In particular, this fixes an unwanted corner case.

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

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

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

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

index dea622706fefb37e807d1cc9f36535ea0a0711bb..2357abd7abdb4f9d1c9cee78cb856eb719c92629 100644 (file)
@@ -170,7 +170,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
 
   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))
index 30bc5b2cd1d6f0c202fe6598ff38a155897fcfd9..ed2658b3c14357ad0a9a66f5a5bec31d3a525f10 100644 (file)
@@ -4662,6 +4662,10 @@ TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {
   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"