[clang] [clang-format] Fix annotation of class name after requires clause (PR #125019)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 29 19:48:56 PST 2025
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/125019
Uncovered in #124891.
>From 1d65fda8b49f44d14511a5a6ea6ee8e45e9ff49c Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Wed, 29 Jan 2025 19:42:11 -0800
Subject: [PATCH] [clang-format] Fix annotation of class name after requires
clause
Uncovered in #124891.
---
clang/lib/Format/TokenAnnotator.cpp | 3 ++-
clang/unittests/Format/TokenAnnotatorTest.cpp | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index a172df5291ae62..43e983f8d0979f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1565,7 +1565,8 @@ class AnnotatingParser {
if (const auto *Previous = Tok->Previous;
!Previous ||
(!Previous->isAttribute() &&
- !Previous->isOneOf(TT_RequiresClause, TT_LeadingJavaAnnotation))) {
+ !Previous->isOneOf(TT_RequiresClause, TT_LeadingJavaAnnotation,
+ TT_BinaryOperator))) {
Line.MightBeFunctionDecl = true;
Tok->MightBeFunctionDeclParen = true;
}
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index fc77e277947c56..7ad7e7fc529f79 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1143,9 +1143,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
EXPECT_TOKEN(Tokens[16], tok::pipepipe, TT_BinaryOperator);
EXPECT_TOKEN(Tokens[21], tok::ampamp, TT_BinaryOperator);
EXPECT_TOKEN(Tokens[27], tok::ampamp, TT_BinaryOperator);
+ // Not TT_TrailingAnnotation.
+ EXPECT_TOKEN(Tokens[28], tok::identifier, TT_Unknown);
EXPECT_TOKEN(Tokens[31], tok::greater, TT_TemplateCloser);
EXPECT_EQ(Tokens[31]->FakeRParens, 1u);
EXPECT_TRUE(Tokens[31]->ClosesRequiresClause);
+ // Not TT_TrailingAnnotation.
+ EXPECT_TOKEN(Tokens[33], tok::identifier, TT_Unknown);
Tokens =
annotate("template<typename T>\n"
More information about the cfe-commits
mailing list