r359687 - [clang-format] Fix bug that misses some function-like macro usages
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Wed May 1 08:03:42 PDT 2019
Author: owenpan
Date: Wed May 1 08:03:41 2019
New Revision: 359687
URL: http://llvm.org/viewvc/llvm-project?rev=359687&view=rev
Log:
[clang-format] Fix bug that misses some function-like macro usages
Fixes PR41483
Differential Revision: https://reviews.llvm.org/D61297
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=359687&r1=359686&r2=359687&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed May 1 08:03:41 2019
@@ -1335,10 +1335,15 @@ void UnwrappedLineParser::parseStructura
// 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();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=359687&r1=359686&r2=359687&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May 1 08:03:41 2019
@@ -2584,6 +2584,12 @@ TEST_F(FormatTest, MacrosWithoutTrailing
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) {
More information about the cfe-commits
mailing list