diff options
| author | Daniel Jasper <djasper@google.com> | 2013-08-27 08:43:47 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-08-27 08:43:47 +0000 |
| commit | cb3f0ed817b1e53a583058cd74ad2f4e03c81f8a (patch) | |
| tree | bf975940265ba8b52d94c69b613bb3b84668ff1f | |
| parent | 12f24673e067f8820db6db778899f8640696dd9f (diff) | |
| download | bcm5719-llvm-cb3f0ed817b1e53a583058cd74ad2f4e03c81f8a.tar.gz bcm5719-llvm-cb3f0ed817b1e53a583058cd74ad2f4e03c81f8a.zip | |
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}};
llvm-svn: 189327
| -rw-r--r-- | clang/lib/Format/FormatToken.cpp | 8 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 24a296adc24..e6c72ab0de9 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index fed054d0aea..19a764cc6c5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) { |

