summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp18
-rw-r--r--clang/unittests/Format/FormatTest.cpp11
2 files changed, 17 insertions, 12 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index a7536d2d244..03921b04b1e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1546,14 +1546,18 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
Style.Language == FormatStyle::LK_Proto) {
// Don't enums onto single lines in protocol buffers.
return true;
- } else if ((Left.is(tok::l_brace) && Left.MatchingParen &&
- Left.MatchingParen->Previous &&
- Left.MatchingParen->Previous->is(tok::comma)) ||
- (Right.is(tok::r_brace) && Left.is(tok::comma))) {
- // If the last token before a '}' is a comma, the intention is to insert a
- // line break after it in order to make shuffling around entries easier.
- return true;
}
+
+ // If the last token before a '}' is a comma, the intention is to insert a
+ // line break after it in order to make shuffling around entries easier.
+ const FormatToken *BeforeClosingBrace = nullptr;
+ if (Left.is(tok::l_brace) && Left.MatchingParen)
+ BeforeClosingBrace = Left.MatchingParen->getPreviousNonComment();
+ else if (Right.is(tok::r_brace))
+ BeforeClosingBrace = Right.getPreviousNonComment();
+ if (BeforeClosingBrace && BeforeClosingBrace->is(tok::comma))
+ return true;
+
return false;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 975f9c6939b..5adc0d5725b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5129,13 +5129,14 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
" 1, 1, 1, 1, 1, 1, 1, 1,\n"
"};",
getLLVMStyleWithColumns(39));
- verifyFormat("vector<int> x = {1, 1, 1, 1,\n"
- " 1, 1, 1, 1, //\n"
+ verifyFormat("vector<int> x = {\n"
+ " 1, 1, 1, 1, 1, 1, 1, 1, //\n"
"};",
getLLVMStyleWithColumns(39));
- verifyFormat("vector<int> x = {1, 1, 1, 1,\n"
- " 1, 1, 1, 1,\n"
- " /**/ /**/};",
+ verifyFormat("vector<int> x = {\n"
+ " 1, 1, 1, 1, 1, 1, 1, 1,\n"
+ " /**/ /**/\n"
+ "};",
getLLVMStyleWithColumns(39));
verifyFormat("return {{aaaaaaaaaaaaaaaaaaaaa},\n"
" {aaaaaaaaaaaaaaaaaaa},\n"
OpenPOWER on IntegriCloud