]> granicus.if.org Git - clang/commitdiff
clang-format: Handle multiline strings inside ternary expressions.
authorDaniel Jasper <djasper@google.com>
Tue, 10 Jun 2014 06:27:23 +0000 (06:27 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 10 Jun 2014 06:27:23 +0000 (06:27 +0000)
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

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

index 308fc623d8217638dd28f8f8fdac4dcb776ae4ea..5d59f19edfbed122214e271793c0df33d2830432 100644 (file)
@@ -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) &&
index cf5c9ff1efb5eea795526d295907138ffe97bc53..584ecba98661ed484f09f214f87799a102121cb1 100644 (file)
@@ -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\");",