-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[clang-format] Fix a regression of annotating PointerOrReference #149039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFixes #149010 Full diff: https://github.com/llvm/llvm-project/pull/149039.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 739209a5681f8..176c9c278b18c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3112,7 +3112,7 @@ class AnnotatingParser {
// It's more likely that & represents operator& than an uninitialized
// reference.
- if (Tok.is(tok::amp) && PrevToken && PrevToken->Tok.isAnyIdentifier() &&
+ if (Tok.is(tok::amp) && PrevToken->Tok.isAnyIdentifier() &&
IsChainedOperatorAmpOrMember(PrevToken->getPreviousNonComment()) &&
NextToken && NextToken->Tok.isAnyIdentifier()) {
if (auto NextNext = NextToken->getNextNonComment();
@@ -3122,6 +3122,9 @@ class AnnotatingParser {
}
}
+ if (PrevToken->isTypeName(LangOpts))
+ return TT_PointerOrReference;
+
if (Line.Type == LT_SimpleRequirement ||
(!Scopes.empty() && Scopes.back() == ST_CompoundRequirement)) {
return TT_BinaryOperator;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e281a4945a862..30942c461427a 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -390,6 +390,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_CompoundRequirementLBrace);
EXPECT_TOKEN(Tokens[22], tok::star, TT_BinaryOperator);
+ Tokens = annotate("bool foo = requires { static_cast<int &&>(1); };");
+ ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+ EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_PointerOrReference);
+
Tokens = annotate("return s.operator int *();");
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
// Not TT_FunctionDeclarationName.
|
HazardyKnusperkeks
approved these changes
Jul 17, 2025
/cherry-pick a8f5e9e |
/pull-request #149451 |
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Jul 22, 2025
…m#149039) Fixes llvm#149010 (cherry picked from commit a8f5e9e)
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.
Fixes #149010