aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/FormatToken.cpp4
-rw-r--r--clang/unittests/Format/FormatTest.cpp15
2 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 7a2df8c..b791c5a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -113,8 +113,8 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
if (!State.NextToken || !State.NextToken->Previous)
return 0;
- if (Formats.size() == 1)
- return 0; // Handled by formatFromToken
+ if (Formats.size() <= 1)
+ return 0; // Handled by formatFromToken (1) or avoid severe penalty (0).
// Ensure that we start on the opening brace.
const FormatToken *LBrace =
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 25ef5c6..c346f38 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13875,6 +13875,21 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
getLLVMStyleWithColumns(35));
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa, {},\n"
" aaaaaaaaaaaaaaaaaaaaaaa);");
+
+ // No possible column formats, don't want the optimal paths penalized.
+ verifyFormat(
+ "waarudo::unit desk = {\n"
+ " .s = \"desk\", .p = p, .b = [] { return w::r{3, 10} * w::m; }};");
+ verifyFormat("SomeType something1([](const Input &i) -> Output { return "
+ "Output{1, 2}; },\n"
+ " [](const Input &i) -> Output { return "
+ "Output{1, 2}; });");
+ FormatStyle NoBinPacking = getLLVMStyle();
+ NoBinPacking.BinPackParameters = false;
+ verifyFormat("waarudo::unit desk = {\n"
+ " .s = \"desk\", .p = p, .b = [] { return w::r{3, 10, 1, 1, "
+ "1, 1} * w::m; }};",
+ NoBinPacking);
}
TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {