summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-06-10 06:27:23 +0000
committerDaniel Jasper <djasper@google.com>2014-06-10 06:27:23 +0000
commit3251fff0e3d1fa4389ccef5ffa3223e47739f5af (patch)
tree4fb5178b255907bc93fa2d402e152cca1f204b8b
parented2c033b9beed8448945e340195ec426ef73ffdd (diff)
downloadbcm5719-llvm-3251fff0e3d1fa4389ccef5ffa3223e47739f5af.tar.gz
bcm5719-llvm-3251fff0e3d1fa4389ccef5ffa3223e47739f5af.zip
clang-format: Handle multiline strings inside ternary expressions.
With AlwaysSplitBeforeMultilineStrings, clang-format would not find any valid solution. llvm-svn: 210513
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp3
-rw-r--r--clang/unittests/Format/FormatTest.cpp6
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 308fc623d82..5d59f19edfb 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index cf5c9ff1efb..584ecba9866 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/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\");",
OpenPOWER on IntegriCloud