From 9d37b395c7e750e5de0bf23fb4bc2755125d3d21 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 19 Jun 2015 10:32:28 +0000 Subject: [PATCH] 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"); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240129 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 2 +- unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index dea622706f..2357abd7ab 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 30bc5b2cd1..ed2658b3c1 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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" -- 2.40.0