llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: None (llvmbot)

<details>
<summary>Changes</summary>

Backport 29f79ea3c59649f7686a09845665660c25ca3f9b

Requested by: @<!-- -->owenca

---
Full diff: https://github.com/llvm/llvm-project/pull/142282.diff


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+6-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+7) 


``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 11b941c5a0411..6ef2d665e1bc4 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3967,8 +3967,13 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
        Tok; Tok = Tok->Next) {
     if (Tok->is(TT_StartOfName))
       SeenName = true;
-    if (Tok->Previous->EndsCppAttributeGroup)
+    const auto *Previous = Tok->Previous;
+    if (Previous->EndsCppAttributeGroup) {
       AfterLastAttribute = Tok;
+    } else if (Line.InMacroBody &&
+               Previous->endsSequence(tok::hashhash, TT_StartOfName)) {
+      Tok->setType(TT_StartOfName);
+    }
     if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
         IsCtorOrDtor ||
         isFunctionDeclarationName(LangOpts, *Tok, Line, ClosingParen)) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 757db66c3e298..2328dce8df8dc 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2187,6 +2187,13 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionDeclarationNames) {
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
 
+  Tokens = annotate("#define FUNC(foo, bar) \\\n"
+                    "  auto foo##bar() -> Type {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_paren, TT_FunctionDeclarationLParen);
+  EXPECT_TOKEN(Tokens[14], tok::arrow, TT_TrailingReturnArrow);
+
   Tokens = annotate("int iso_time(time_t);");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);

``````````

</details>


https://github.com/llvm/llvm-project/pull/142282
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to