[clang] 037657d - [clang-format] Correctly annotate kw_operator in using decls (#136545)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 22 21:09:00 PDT 2025
Author: Owen Pan
Date: 2025-04-22T21:08:56-07:00
New Revision: 037657de7e5ccd4a37054829874a209b82fb8be7
URL: https://github.com/llvm/llvm-project/commit/037657de7e5ccd4a37054829874a209b82fb8be7
DIFF: https://github.com/llvm/llvm-project/commit/037657de7e5ccd4a37054829874a209b82fb8be7.diff
LOG: [clang-format] Correctly annotate kw_operator in using decls (#136545)
Fix #136541
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index b4f303e281c1d..6d861d19117e2 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3977,8 +3977,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
FormatToken *AfterLastAttribute = nullptr;
FormatToken *ClosingParen = nullptr;
- for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr; Tok;
- Tok = Tok->Next) {
+ for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
+ ? FirstNonComment->Next
+ : nullptr;
+ Tok; Tok = Tok->Next) {
if (Tok->is(TT_StartOfName))
SeenName = true;
if (Tok->Previous->EndsCppAttributeGroup)
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e540af85aff3a..87b2f329d57cf 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1084,6 +1084,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
+
+ Tokens = annotate("using std::operator==;");
+ ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ // Not TT_FunctionDeclarationName.
+ EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_Unknown);
}
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {
More information about the cfe-commits
mailing list