From: Daniel Jasper Date: Tue, 15 Jul 2014 09:00:34 +0000 (+0000) Subject: clang-format: Improve heuristic around avoiding bad line breaks. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0398cdfb559093639263bfe424e6bfb9d63f9893;p=clang clang-format: Improve heuristic around avoiding bad line breaks. Now, this can be properly formatted: static_cast *>( // ); Before, clang-format could end up, not formatting the code at all. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213055 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 2af16fcd0c..014c30e346 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -108,7 +108,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) { // ... // As they hide "DoSomething" and are generally bad for readability. if (Previous.opensScope() && Previous.isNot(tok::l_brace) && - State.LowestLevelOnLine < State.StartOfLineLevel) + State.LowestLevelOnLine < State.StartOfLineLevel && + State.LowestLevelOnLine < Current.NestingLevel) return false; if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder) return false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 81b233c2f5..2ac017c6f5 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4467,6 +4467,14 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(\n" " bbbbbbbbbbbbbbbbbbbbbbbb);", getLLVMStyleWithColumns(72)); + EXPECT_EQ("static_cast *>(\n" + "\n" + " );", + format("static_cast*>(\n" + "\n" + " );")); FormatStyle AlwaysBreak = getLLVMStyle(); AlwaysBreak.AlwaysBreakTemplateDeclarations = true;