diff options
author | Owen Pan <owenpiano@gmail.com> | 2019-05-01 15:03:41 +0000 |
---|---|---|
committer | Owen Pan <owenpiano@gmail.com> | 2019-05-01 15:03:41 +0000 |
commit | f1f9d1bbc248fc274711984e89e4923fd0d81db8 (patch) | |
tree | c082f3625649f724078e8b7dd09520ebc4d611f5 | |
parent | 056b030299b4d15dec39445fbd531242370c536c (diff) |
[clang-format] Fix bug that misses some function-like macro usages
Fixes PR41483
Differential Revision: https://reviews.llvm.org/D61297
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359687 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 13 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 6 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 64890d5333..7acf33a968 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1335,10 +1335,15 @@ void UnwrappedLineParser::parseStructuralElement() { // See if the following token should start a new unwrapped line. StringRef Text = FormatTok->TokenText; nextToken(); - if (Line->Tokens.size() == 1 && - // JS doesn't have macros, and within classes colons indicate fields, - // not labels. - Style.Language != FormatStyle::LK_JavaScript) { + + // JS doesn't have macros, and within classes colons indicate fields, not + // labels. + if (Style.Language == FormatStyle::LK_JavaScript) + break; + + TokenCount = Line->Tokens.size(); + if (TokenCount == 1 || + (TokenCount == 2 && Line->Tokens.front().Tok->is(tok::comment))) { if (FormatTok->Tok.is(tok::colon) && !Line->MustBeDeclaration) { Line->Tokens.begin()->Tok->MustBreakBefore = true; parseLabel(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d269aab02e..fd61470d65 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2584,6 +2584,12 @@ TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) { verifyFormat("VISIT_GL_CALL(GenBuffers, void, (GLsizei n, GLuint* buffers), " "(n, buffers))\n", getChromiumStyle(FormatStyle::LK_Cpp)); + + // See PR41483 + EXPECT_EQ("/**/ FOO(a)\n" + "FOO(b)", + format("/**/ FOO(a)\n" + "FOO(b)")); } TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) { |