r291801 - clang-format: Treat braced lists like other complex parameters.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 12 11:35:26 PST 2017
Author: djasper
Date: Thu Jan 12 13:35:26 2017
New Revision: 291801
URL: http://llvm.org/viewvc/llvm-project?rev=291801&view=rev
Log:
clang-format: Treat braced lists like other complex parameters.
Specifically, wrap before them if they are multi-line so that we don't
create long hanging indents. This prevents having a lot of code
indented a lot in some cases.
Before:
someFunction(Param, {List1, List2,
List3});
After:
someFunction(Param,
{List1, List2,
List3});
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=291801&r1=291800&r2=291801&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Jan 12 13:35:26 2017
@@ -930,6 +930,13 @@ void ContinuationIndenter::moveStatePast
return;
}
+ const FormatToken *Previous = Current.getPreviousNonComment();
+ if (Previous && Previous->is(tok::comma) &&
+ !Previous->is(TT_OverloadedOperator)) {
+ if (!Newline)
+ State.Stack.back().NoLineBreak = true;
+ }
+
unsigned NewIndent;
unsigned NewIndentLevel = State.Stack.back().IndentLevel;
unsigned LastSpace = State.Stack.back().LastSpace;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=291801&r1=291800&r2=291801&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 12 13:35:26 2017
@@ -6816,6 +6816,12 @@ TEST_F(FormatTest, FormatsBracedListsInC
" aaaaaa.aaaaaaa,\n"
" aaaaaa.aaaaaaa,\n"
"};");
+
+ // Don't create hanging lists.
+ verifyFormat("someFunction(Param,\n"
+ " {List1, List2,\n"
+ " List3});",
+ getLLVMStyleWithColumns(35));
}
TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
More information about the cfe-commits
mailing list