diff options
| author | Daniel Jasper <djasper@google.com> | 2015-07-15 16:26:47 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2015-07-15 16:26:47 +0000 |
| commit | 00fb2a118398e2d8d9f5f246db8f746d2aec69d6 (patch) | |
| tree | 970d1e39831e6f5f565572204dc3076d8334adee | |
| parent | 2e0133526e85e53ff67a25511b9789d2e10f17d2 (diff) | |
| download | bcm5719-llvm-00fb2a118398e2d8d9f5f246db8f746d2aec69d6.tar.gz bcm5719-llvm-00fb2a118398e2d8d9f5f246db8f746d2aec69d6.zip | |
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
};
llvm-svn: 242299
| -rw-r--r-- | clang/lib/Format/FormatToken.cpp | 3 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 6c244c31660..358a9a48ec8 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -183,7 +183,8 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { 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) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d61dc7f662c..886f58093de 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6307,6 +6307,11 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { " 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. |

