From: Daniel Jasper Date: Mon, 11 Jan 2016 11:01:05 +0000 (+0000) Subject: clang-format: Slightly row back on r257257. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4764e0cdd604e9f7b7f89eaebf92a525b09ff6ae;p=clang clang-format: Slightly row back on r257257. r257257 change the way clang-format enforces line breaks after a templated type has been line-wrapped. This was to fix an incorrect line break if BinPackParameters is set to false. However, it also leads to an unwanted line break in a different case. Thus, for now, only do this when BinPackParameters is false. This isn't ideal yet, but helps us until we have a better solution. With BinPackParameters: Before: void fffffffffff(aaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaa); After: void fffffffffff( aaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaa); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257325 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index cb5999e60e..a6a5a1d809 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -151,7 +151,11 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { return true; if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) || (Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) && - Previous.NestingLevel == 1) || + // FIXME: This is a temporary workaround for the case where clang-format + // sets BreakBeforeParameter to avoid bin packing and this creates a + // completely unnecessary line break after a template type that isn't + // line-wrapped. + (Previous.NestingLevel == 1 || Style.BinPackParameters)) || (Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) && Previous.isNot(tok::question)) || (!Style.BreakBeforeTernaryOperators && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index fe673cc486..f9a80d0580 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4062,10 +4062,23 @@ TEST_F(FormatTest, FormatsDeclarationsOnePerLine) { " int aaaaaaaaaaaaaaaaaaaa,\n" " int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}", NoBinPacking); + NoBinPacking.AllowAllParametersOfDeclarationOnNextLine = false; verifyFormat("void aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " vector bbbbbbbbbbbbbbb);", NoBinPacking); + // FIXME: This behavior difference is probably not wanted. However, currently + // we cannot distinguish BreakBeforeParameter being set because of the wrapped + // template arguments from BreakBeforeParameter being set because of the + // one-per-line formatting. + verifyFormat( + "void fffffffffff(aaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaa);", + NoBinPacking); + verifyFormat( + "void fffffffffff(\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " aaaaaaaaaa);"); } TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {