release/20.x: [clang-format] Correctly annotate kw_operator in using decls (#136545)#136808
Merged
Conversation
Member
Author
|
@HazardyKnusperkeks What do you think about merging this PR to the release branch? |
Member
Author
|
@llvm/pr-subscribers-clang-format Author: None (llvmbot) ChangesBackport 037657d Requested by: @owenca Full diff: https://github.com/llvm/llvm-project/pull/136808.diff 2 Files Affected:
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) {
|
HazardyKnusperkeks
approved these changes
Apr 23, 2025
…6545) Fix llvm#136541 (cherry picked from commit 037657d)
|
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 037657d
Requested by: @owenca