From 1a0fd5b2763781f8b38abd9fdab226eb0869c004 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 19 Dec 2016 11:14:23 +0000 Subject: [PATCH] clang-format: Slightly tweak the behavior of <<-wrapping. Before: SomeLongLoggingStatementOrMacro() << "Some long text " << some_variable << "\n"; Before: SomeLongLoggingStatementOrMacro() << "Some long text " << some_variable << "\n"; Short logging statements are already special cased in a different part of the code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290094 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 2 +- lib/Format/TokenAnnotator.cpp | 9 +++++++-- unittests/Format/FormatTest.cpp | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index aa6f37bd19..bf075ab6d5 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -460,7 +460,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, Penalty += State.NextToken->SplitPenalty; // Breaking before the first "<<" is generally not desirable if the LHS is - // short. Also always add the penalty if the LHS is split over mutliple lines + // short. Also always add the penalty if the LHS is split over multiple lines // to avoid unnecessary line breaks that just work around this penalty. if (NextNonComment->is(tok::lessless) && State.Stack.back().FirstLessLess == 0 && diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 77b6a5d4d2..5dcaf2651f 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2007,8 +2007,13 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Right.isOneOf(tok::lessless, tok::plus) && Left.isLabelString() && (Right.NextOperator || Right.OperatorIndex != 1)) return 25; - if (Right.is(tok::lessless)) - return 1; // Breaking at a << is really cheap. + if (Right.is(tok::lessless)) { + // Breaking at a << is really cheap. + if (!Left.is(tok::r_paren) || Right.OperatorIndex > 0) + // Slightly prefer to break before the first one in log-like statements. + return 2; + return 1; + } if (Left.is(TT_ConditionalExpr)) return prec::Conditional; prec::Level Level = Left.getPrecedence(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9c2c25d091..af78419706 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5091,6 +5091,9 @@ TEST_F(FormatTest, AlignsPipes) { verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << aaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " << aaaaaaaaaaaaaaaaaaaaaaaaaaaa;"); + verifyFormat( + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n" + " << aaaaaaaaaaaaaaaaaaaaaaaaaaaa << aaaaaaaaaaaaaaaaaaaaaaaaaaaa;"); verifyFormat( "llvm::outs() << \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"\n" -- 2.40.0