Skip to content

release/20.x: [clang-format] Correctly annotate kw_operator in using decls (#136545)#136808

Merged
tstellar merged 1 commit into
llvm:release/20.xfrom
llvmbot:issue136545
Apr 25, 2025
Merged

release/20.x: [clang-format] Correctly annotate kw_operator in using decls (#136545)#136808
tstellar merged 1 commit into
llvm:release/20.xfrom
llvmbot:issue136545

Conversation

@llvmbot

@llvmbot llvmbot commented Apr 23, 2025

Copy link
Copy Markdown
Member

Backport 037657d

Requested by: @owenca

@llvmbot

llvmbot commented Apr 23, 2025

Copy link
Copy Markdown
Member Author

@HazardyKnusperkeks What do you think about merging this PR to the release branch?

@llvmbot

llvmbot commented Apr 23, 2025

Copy link
Copy Markdown
Member Author

@llvm/pr-subscribers-clang-format

Author: None (llvmbot)

Changes

Backport 037657d

Requested by: @owenca


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

2 Files Affected:

  • (modified) clang/lib/Format/TokenAnnotator.cpp (+4-2)
  • (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 44580d8624684..11b941c5a0411 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3961,8 +3961,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 b7b8a21b726b6..757db66c3e298 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1073,6 +1073,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) {

@github-project-automation github-project-automation Bot moved this from Needs Triage to Needs Merge in LLVM Release Status Apr 23, 2025
@tstellar
tstellar merged commit 182e8b7 into llvm:release/20.x Apr 25, 2025
@github-project-automation github-project-automation Bot moved this from Needs Merge to Done in LLVM Release Status Apr 25, 2025
@github-actions

Copy link
Copy Markdown

@owenca (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants