diff options
-rw-r--r-- | clang/lib/Format/FormatToken.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 180e537ce06..e0dfac7d4e1 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -273,7 +273,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { continue; // Ignore layouts that are bound to violate the column limit. - if (Format.TotalWidth > Style.ColumnLimit) + if (Format.TotalWidth > Style.ColumnLimit && Columns > 1) continue; Formats.push_back(Format); @@ -287,7 +287,7 @@ CommaSeparatedList::getColumnFormat(unsigned RemainingCharacters) const { I = Formats.rbegin(), E = Formats.rend(); I != E; ++I) { - if (I->TotalWidth <= RemainingCharacters) { + if (I->TotalWidth <= RemainingCharacters || I->Columns == 1) { if (BestFormat && I->LineCount > BestFormat->LineCount) break; BestFormat = &*I; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index adf529cfeda..70abf3af7d7 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6779,6 +6779,18 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { " 1, 22, 333, 4444, 55555, 666666, 7777777,\n" " 1, 22, 333, 4444, 55555, 666666, 7777777,\n" " 1, 22, 333, 4444, 55555, 666666, 7777777});"); + + // Allow "single-column" layout even if that violates the column limit. There + // isn't going to be a better way. + verifyFormat("std::vector<int> a = {\n" + " aaaaaaaa,\n" + " aaaaaaaa,\n" + " aaaaaaaa,\n" + " aaaaaaaa,\n" + " aaaaaaaaaa,\n" + " aaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaa};", + getLLVMStyleWithColumns(30)); } TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { |