[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
github-actions[bot] wrote: @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. https://github.com/llvm/llvm-project/pull/149451 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
https://github.com/tru closed https://github.com/llvm/llvm-project/pull/149451 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/149451
>From 607677c86185fd1979754e8c2803e168bbf8f9a9 Mon Sep 17 00:00:00 2001
From: Owen Pan
Date: Thu, 17 Jul 2025 21:43:43 -0700
Subject: [PATCH] [clang-format] Fix a regression of annotating
PointerOrReference (#149039)
Fixes #149010
(cherry picked from commit a8f5e9ed6b44562938ce07e2790be90be8f0a6b5)
---
clang/lib/Format/TokenAnnotator.cpp | 10 +++---
clang/unittests/Format/TokenAnnotatorTest.cpp | 4
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp
b/clang/lib/Format/TokenAnnotator.cpp
index 739209a5681f8..581bfbab0972d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2996,14 +2996,18 @@ class AnnotatingParser {
const FormatToken *PrevToken = Tok.getPreviousNonComment();
if (!PrevToken)
return TT_UnaryOperator;
-if (PrevToken->is(TT_TypeName))
+if (PrevToken->isTypeName(LangOpts))
return TT_PointerOrReference;
if (PrevToken->isPlacementOperator() && Tok.is(tok::ampamp))
return TT_BinaryOperator;
-const FormatToken *NextToken = Tok.getNextNonComment();
+auto *NextToken = Tok.getNextNonComment();
if (!NextToken)
return TT_PointerOrReference;
+if (NextToken->is(tok::greater)) {
+ NextToken->setFinalizedType(TT_TemplateCloser);
+ return TT_PointerOrReference;
+}
if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
return TT_BinaryOperator;
@@ -3112,7 +3116,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();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e281a4945a862..ce7787ede0f5c 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(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.
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/149451 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
https://github.com/llvmbot created
https://github.com/llvm/llvm-project/pull/149451
Backport a8f5e9ed6b44562938ce07e2790be90be8f0a6b5
Requested by: @owenca
>From 24b8c4731093804c8e20ceb5eb5980e6d4c641b1 Mon Sep 17 00:00:00 2001
From: Owen Pan
Date: Thu, 17 Jul 2025 21:43:43 -0700
Subject: [PATCH] [clang-format] Fix a regression of annotating
PointerOrReference (#149039)
Fixes #149010
(cherry picked from commit a8f5e9ed6b44562938ce07e2790be90be8f0a6b5)
---
clang/lib/Format/TokenAnnotator.cpp | 10 +++---
clang/unittests/Format/TokenAnnotatorTest.cpp | 4
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp
b/clang/lib/Format/TokenAnnotator.cpp
index 739209a5681f8..581bfbab0972d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2996,14 +2996,18 @@ class AnnotatingParser {
const FormatToken *PrevToken = Tok.getPreviousNonComment();
if (!PrevToken)
return TT_UnaryOperator;
-if (PrevToken->is(TT_TypeName))
+if (PrevToken->isTypeName(LangOpts))
return TT_PointerOrReference;
if (PrevToken->isPlacementOperator() && Tok.is(tok::ampamp))
return TT_BinaryOperator;
-const FormatToken *NextToken = Tok.getNextNonComment();
+auto *NextToken = Tok.getNextNonComment();
if (!NextToken)
return TT_PointerOrReference;
+if (NextToken->is(tok::greater)) {
+ NextToken->setFinalizedType(TT_TemplateCloser);
+ return TT_PointerOrReference;
+}
if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
return TT_BinaryOperator;
@@ -3112,7 +3116,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();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e281a4945a862..ce7787ede0f5c 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(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.
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
llvmbot wrote:
@llvm/pr-subscribers-clang-format
Author: None (llvmbot)
Changes
Backport a8f5e9ed6b44562938ce07e2790be90be8f0a6b5
Requested by: @owenca
---
Full diff: https://github.com/llvm/llvm-project/pull/149451.diff
2 Files Affected:
- (modified) clang/lib/Format/TokenAnnotator.cpp (+7-3)
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+4)
``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp
b/clang/lib/Format/TokenAnnotator.cpp
index 739209a5681f8..581bfbab0972d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2996,14 +2996,18 @@ class AnnotatingParser {
const FormatToken *PrevToken = Tok.getPreviousNonComment();
if (!PrevToken)
return TT_UnaryOperator;
-if (PrevToken->is(TT_TypeName))
+if (PrevToken->isTypeName(LangOpts))
return TT_PointerOrReference;
if (PrevToken->isPlacementOperator() && Tok.is(tok::ampamp))
return TT_BinaryOperator;
-const FormatToken *NextToken = Tok.getNextNonComment();
+auto *NextToken = Tok.getNextNonComment();
if (!NextToken)
return TT_PointerOrReference;
+if (NextToken->is(tok::greater)) {
+ NextToken->setFinalizedType(TT_TemplateCloser);
+ return TT_PointerOrReference;
+}
if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
return TT_BinaryOperator;
@@ -3112,7 +3116,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();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e281a4945a862..ce7787ede0f5c 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(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.
``
https://github.com/llvm/llvm-project/pull/149451
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
llvmbot wrote: @HazardyKnusperkeks What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/149451 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang-format] Fix a regression of annotating PointerOrReference (#149039) (PR #149451)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/149451 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
