summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2017-01-12 19:35:26 +0000
committerDaniel Jasper <djasper@google.com>2017-01-12 19:35:26 +0000
commit3840cfcb048c98504efd8e88789b6e5949db9158 (patch)
tree138db1a7f807ee8f002bbbe1a67ca43fc22a1412
parent2d285238fc654aaf1b57310153a0dc29c33104cc (diff)
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}); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291801 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/ContinuationIndenter.cpp7
-rw-r--r--unittests/Format/FormatTest.cpp6
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index bf075ab6d5..5a30370af8 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -930,6 +930,13 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
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;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 629e85803d..640d9bd58b 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -6816,6 +6816,12 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
" 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) {