r189327 - clang-format: Fix bug in column layout.
Daniel Jasper
djasper at google.com
Tue Aug 27 01:43:48 PDT 2013
Author: djasper
Date: Tue Aug 27 03:43:47 2013
New Revision: 189327
URL: http://llvm.org/viewvc/llvm-project?rev=189327&view=rev
Log:
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}};
Modified:
cfe/trunk/lib/Format/FormatToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=189327&r1=189326&r2=189327&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Tue Aug 27 03:43:47 2013
@@ -39,9 +39,13 @@ unsigned CommaSeparatedList::format(Line
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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=189327&r1=189326&r2=189327&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Aug 27 03:43:47 2013
@@ -4195,6 +4195,9 @@ TEST_F(FormatTest, FormatsBracedListsinC
" 1, 1, 1, 1,\n"
" /**/ /**/ };",
getLLVMStyleWithColumns(39));
+ verifyFormat("return { { aaaaaaaaaaaaaaaaaaaaa }, { aaaaaaaaaaaaaaaaaaa },\n"
+ " { aaaaaaaaaaaaaaaaaaaaa }, { aaaaaaaaaaaaaaaaa } };",
+ getLLVMStyleWithColumns(60));
}
TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
More information about the cfe-commits
mailing list