From: Daniel Jasper Date: Tue, 27 Aug 2013 08:43:47 +0000 (+0000) Subject: clang-format: Fix bug in column layout. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=451f1e0e5040db6a114217e7bd9767bf751d5bd3;p=clang clang-format: Fix bug in column layout. Before (with 60 character limit in Google style): return { {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}}; After: return {{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}}; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189327 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp index 24a296adc2..e6c72ab0de 100644 --- a/lib/Format/FormatToken.cpp +++ b/lib/Format/FormatToken.cpp @@ -39,9 +39,13 @@ unsigned CommaSeparatedList::format(LineState &State, LBrace->Next->Type == TT_DesignatedInitializerPeriod) return 0; + // Calculate the number of code points we have to format this list. As the + // first token is already placed, we have to subtract it. + unsigned RemainingCodePoints = Style.ColumnLimit - State.Column + + State.NextToken->Previous->CodePointCount; + // Find the best ColumnFormat, i.e. the best number of columns to use. - unsigned RemainingCharacters = Style.ColumnLimit - State.Stack.back().Indent; - const ColumnFormat *Format = getColumnFormat(RemainingCharacters); + const ColumnFormat *Format = getColumnFormat(RemainingCodePoints); if (!Format) return 0; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index fed054d0ae..19a764cc6c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4195,6 +4195,9 @@ TEST_F(FormatTest, FormatsBracedListsinColumnLayout) { " 1, 1, 1, 1,\n" " /**/ /**/ };", getLLVMStyleWithColumns(39)); + verifyFormat("return { { aaaaaaaaaaaaaaaaaaaaa }, { aaaaaaaaaaaaaaaaaaa },\n" + " { aaaaaaaaaaaaaaaaaaaaa }, { aaaaaaaaaaaaaaaaa } };", + getLLVMStyleWithColumns(60)); } TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {