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
This commit is contained in:
Daniel Jasper 2013-08-27 08:43:47 +00:00
parent 12f24673e0
commit cb3f0ed817
2 changed files with 9 additions and 2 deletions

View File

@ -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;

View File

@ -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) {