summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-12-21 17:02:06 +0000
committerDaniel Jasper <djasper@google.com>2016-12-21 17:02:06 +0000
commit083d1700a0ef03d98db2109fd76186889f3c3fbe (patch)
tree3cec09f948c80ad4324b86a8923f2f09f04b8334
parent12c3f33650dd45b9c95c7f4064e4520b59fd69e6 (diff)
downloadbcm5719-llvm-083d1700a0ef03d98db2109fd76186889f3c3fbe.tar.gz
bcm5719-llvm-083d1700a0ef03d98db2109fd76186889f3c3fbe.zip
clang-format: Fix bug in handling of single-column lists.
Members that are themselves wrapped in fake parentheses would lead to AvoidBinPacking be set on the wrong ParenState. After: vector<int> aaaa = { aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaa.aaaaaaa, aaaaaa.aaaaaaa, aaaaaa.aaaaaaa, aaaaaa.aaaaaaa, }; Before we were falling back to bin-packing these. llvm-svn: 290259
-rw-r--r--clang/lib/Format/FormatToken.cpp14
-rw-r--r--clang/unittests/Format/FormatTest.cpp8
2 files changed, 14 insertions, 8 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index b51f807ccc1..ba5bf03a634 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -77,6 +77,9 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
if (State.NextToken == nullptr || !State.NextToken->Previous)
return 0;
+ if (Formats.size() == 1)
+ return 0; // Handled by formatFromToken
+
// Ensure that we start on the opening brace.
const FormatToken *LBrace =
State.NextToken->Previous->getPreviousNonComment();
@@ -93,13 +96,6 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
// Find the best ColumnFormat, i.e. the best number of columns to use.
const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
- // Formatting with 1 Column isn't really a column layout, so we don't need the
- // special logic here. We can just avoid bin packing any of the parameters.
- if (Format && Format->Columns == 1) {
- State.Stack.back().AvoidBinPacking = true;
- return 0;
- }
-
// If no ColumnFormat can be used, the braced list would generally be
// bin-packed. Add a severe penalty to this so that column layouts are
// preferred if possible.
@@ -137,7 +133,9 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
unsigned CommaSeparatedList::formatFromToken(LineState &State,
ContinuationIndenter *Indenter,
bool DryRun) {
- if (HasNestedBracedList)
+ // Formatting with 1 Column isn't really a column layout, so we don't need the
+ // special logic here. We can just avoid bin packing any of the parameters.
+ if (Formats.size() == 1 || HasNestedBracedList)
State.Stack.back().AvoidBinPacking = true;
return 0;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 27c946e6ff0..75d352bc6d9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6800,6 +6800,14 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
" aaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa};",
getLLVMStyleWithColumns(30));
+ verifyFormat("vector<int> aaaa = {\n"
+ " aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaa.aaaaaaa,\n"
+ " aaaaaa.aaaaaaa,\n"
+ " aaaaaa.aaaaaaa,\n"
+ " aaaaaa.aaaaaaa,\n"
+ "};");
}
TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
OpenPOWER on IntegriCloud