summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/Format.cpp2
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTest.cpp33
3 files changed, 24 insertions, 13 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 55107765f1f..e0a05b64ecc 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -556,7 +556,7 @@ private:
if (!DryRun) {
unsigned NewLines = 1;
- if (Current.Type == TT_LineComment)
+ if (Current.is(tok::comment))
NewLines = std::max(
NewLines,
std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 20709bbb306..85c5a36a0a7 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -902,7 +902,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
spaceRequiredBefore(Line, *Current) ? 1 : 0;
if (Current->MustBreakBefore) {
- } else if (Current->Type == TT_LineComment) {
+ } else if (Current->is(tok::comment)) {
Current->MustBreakBefore = Current->NewlinesBefore > 0;
} else if (Current->Previous->isTrailingComment() ||
(Current->is(tok::string_literal) &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 3a4cd8d3244..c8bd945380a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1181,11 +1181,20 @@ TEST_F(FormatTest, CommentsInStaticInitializers) {
" // Comment after empty line\n"
" b\n"
"}"));
- EXPECT_EQ("S s = { a, b };", format("S s = {\n"
- " a,\n"
- "\n"
- " b\n"
- "};"));
+ EXPECT_EQ("S s = {\n"
+ " /* Some comment */\n"
+ " a,\n"
+ "\n"
+ " /* Comment after empty line */\n"
+ " b\n"
+ "}",
+ format("S s = {\n"
+ " /* Some comment */\n"
+ " a,\n"
+ " \n"
+ " /* Comment after empty line */\n"
+ " b\n"
+ "}"));
verifyFormat("const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {\n"
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
@@ -1530,6 +1539,11 @@ TEST_F(FormatTest, StaticInitializers) {
verifyFormat("static int LooooooooooooooooooooooooongVariable[1] = {\n"
" 100000000000000000000000\n"
"};");
+ EXPECT_EQ("S s = { a, b };", format("S s = {\n"
+ " a,\n"
+ "\n"
+ " b\n"
+ "};"));
// FIXME: This would fit into the column limit if we'd fit "{ {" on the first
// line. However, the formatting looks a bit off and this probably doesn't
@@ -3855,15 +3869,13 @@ TEST_F(FormatTest, BlockCommentsAtEndOfLine) {
EXPECT_EQ("a = {\n"
" 1111 /* */\n"
"};",
- format("a = {1111\n"
- "/* */\n"
+ format("a = {1111 /* */\n"
"};",
getLLVMStyleWithColumns(15)));
EXPECT_EQ("a = {\n"
" 1111 /* */\n"
"};",
- format("a = {1111\n"
- "/* */\n"
+ format("a = {1111 /* */\n"
"};",
getLLVMStyleWithColumns(15)));
@@ -3872,8 +3884,7 @@ TEST_F(FormatTest, BlockCommentsAtEndOfLine) {
" 1111 /* a\n"
" */\n"
"};",
- format("a = {1111\n"
- "/* a */\n"
+ format("a = {1111 /* a */\n"
"};",
getLLVMStyleWithColumns(15)));
}
OpenPOWER on IntegriCloud