]> granicus.if.org Git - clang/commitdiff
[clang-format] Fix bug that misses some function-like macro usages
authorOwen Pan <owenpiano@gmail.com>
Wed, 1 May 2019 15:03:41 +0000 (15:03 +0000)
committerOwen Pan <owenpiano@gmail.com>
Wed, 1 May 2019 15:03:41 +0000 (15:03 +0000)
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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 64890d5333c81155603a018d8ecb2b89a0c09ac2..7acf33a96804d4e79fa7cb1a024528cbcbef9cce 100644 (file)
@@ -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();
index d269aab02ed4c542dbcfdf6d5332b6f1b2cd8597..fd61470d656b0cc22260488ad4f375378ab7f577 100644 (file)
@@ -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) {