r213055 - clang-format: Improve heuristic around avoiding bad line breaks.
Daniel Jasper
djasper at google.com
Tue Jul 15 02:00:34 PDT 2014
Author: djasper
Date: Tue Jul 15 04:00:34 2014
New Revision: 213055
URL: http://llvm.org/viewvc/llvm-project?rev=213055&view=rev
Log:
clang-format: Improve heuristic around avoiding bad line breaks.
Now, this can be properly formatted:
static_cast<A< //
B> *>( //
);
Before, clang-format could end up, not formatting the code at all.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=213055&r1=213054&r2=213055&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Jul 15 04:00:34 2014
@@ -108,7 +108,8 @@ bool ContinuationIndenter::canBreak(cons
// ...
// 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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=213055&r1=213054&r2=213055&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jul 15 04:00:34 2014
@@ -4467,6 +4467,14 @@ TEST_F(FormatTest, WrapsTemplateDeclarat
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(\n"
" bbbbbbbbbbbbbbbbbbbbbbbb);",
getLLVMStyleWithColumns(72));
+ EXPECT_EQ("static_cast<A< //\n"
+ " B> *>(\n"
+ "\n"
+ " );",
+ format("static_cast<A<//\n"
+ " B>*>(\n"
+ "\n"
+ " );"));
FormatStyle AlwaysBreak = getLLVMStyle();
AlwaysBreak.AlwaysBreakTemplateDeclarations = true;
More information about the cfe-commits
mailing list