From: Daniel Jasper <djasper@google.com>
Date: Tue, 10 Jun 2014 06:27:23 +0000 (+0000)
Subject: clang-format: Handle multiline strings inside ternary expressions.
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c5e47d7fb3f3283ecb9712fc42fb7ad62dcb63bd;p=clang

clang-format: Handle multiline strings inside ternary expressions.

With AlwaysSplitBeforeMultilineStrings, clang-format would not find any
valid solution.

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

diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index 308fc623d8..5d59f19edf 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -146,7 +146,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
   if (Style.AlwaysBreakBeforeMultilineStrings &&
       State.Column > State.Stack.back().Indent && // Breaking saves columns.
       !Previous.isOneOf(tok::kw_return, tok::lessless, tok::at) &&
-      Previous.Type != TT_InlineASMColon && nextIsMultilineString(State))
+      Previous.Type != TT_InlineASMColon &&
+      Previous.Type != TT_ConditionalExpr && nextIsMultilineString(State))
     return true;
   if (((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||
        Previous.Type == TT_ArrayInitializerLSquare) &&
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index cf5c9ff1ef..584ecba986 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -4167,6 +4167,12 @@ TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) {
                "     L\"cccc\");",
                Break);
 
+  // As we break before unary operators, breaking right after them is bad.
+  verifyFormat("string foo = abc ? \"x\"\n"
+               "                   \"blah blah blah blah blah blah\"\n"
+               "                 : \"y\";",
+               Break);
+
   // Don't break if there is no column gain.
   verifyFormat("f(\"aaaa\"\n"
                "  \"bbbb\");",