r242299 - clang-format: Fix column layout with a comment in the last line.
Daniel Jasper
djasper at google.com
Wed Jul 15 09:26:48 PDT 2015
Author: djasper
Date: Wed Jul 15 11:26:47 2015
New Revision: 242299
URL: http://llvm.org/viewvc/llvm-project?rev=242299&view=rev
Log:
clang-format: Fix column layout with a comment in the last line.
Before:
int aaaaa[] = {
1, 2,
3, // comment
4, 5,
6 // comment
};
After:
int aaaaa[] = {
1, 2, 3, // comment
4, 5, 6 // comment
};
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=242299&r1=242298&r2=242299&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Wed Jul 15 11:26:47 2015
@@ -183,7 +183,8 @@ void CommaSeparatedList::precomputeForma
ItemEnd = Token->MatchingParen;
const FormatToken *NonCommentEnd = ItemEnd->getPreviousNonComment();
ItemLengths.push_back(CodePointsBetween(ItemBegin, NonCommentEnd));
- if (Style.Cpp11BracedListStyle) {
+ if (Style.Cpp11BracedListStyle &&
+ !ItemEnd->Previous->isTrailingComment()) {
// In Cpp11 braced list style, the } and possibly other subsequent
// tokens will need to stay on a line with the last element.
while (ItemEnd->Next && !ItemEnd->Next->CanBreakBefore)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=242299&r1=242298&r2=242299&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jul 15 11:26:47 2015
@@ -6307,6 +6307,11 @@ TEST_F(FormatTest, FormatsBracedListsInC
" 1111111111, 2222222222, 33333333333, 4444444444, //\n"
" 111111111, 222222222, 3333333333, 444444444, //\n"
" 11111111, 22222222, 333333333, 44444444};");
+ // Trailing comment in the last line.
+ verifyFormat("int aaaaa[] = {\n"
+ " 1, 2, 3, // comment\n"
+ " 4, 5, 6 // comment\n"
+ "};");
// With nested lists, we should either format one item per line or all nested
// lists one on line.
More information about the cfe-commits
mailing list