https://github.com/ZenginU updated 
https://github.com/llvm/llvm-project/pull/226739

>From 585393c47572efe2e5ebf047a4e7fd54ec8b76df Mon Sep 17 00:00:00 2001
From: ZenginU <[email protected]>
Date: Sat, 26 Sep 2026 18:33:36 -0400
Subject: [PATCH 1/2] Fix: Fix when std::ranges::fix is offered on a pointer
 type.

---
 .../clang-tidy/utils/UseRangesCheck.cpp           | 15 +++++++++++----
 .../clang-tidy/checkers/modernize/use-ranges.cpp  | 15 ++++++++++++++-
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index e66e1e541e461..6529c23ee5cb6 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "UseRangesCheck.h"
+#include "FixItHintUtils.h"
 #include "Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
@@ -268,13 +269,19 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
     for (const auto &[First, Second, Replace] : Sig) {
       auto ArgNode = ArgName + std::to_string(First);
       if (const auto *ArgExpr = Result.Nodes.getNodeAs<Expr>(ArgNode)) {
-        Diag << FixItHint::CreateReplacement(
-            Call->getArg(Replace == Indexes::Second ? Second : First)
-                ->getSourceRange(),
+        const Expr *RangeArg =
+            Call->getArg(Replace == Indexes::Second ? Second : First);
+        std::string ReplaceText =
             Lexer::getSourceText(
                 CharSourceRange::getTokenRange(ArgExpr->getSourceRange()),
                 Result.Context->getSourceManager(),
-                Result.Context->getLangOpts()));
+                Result.Context->getLangOpts())
+                .str();
+        if (ArgExpr->getType()->isPointerType() &&
+            isa<CXXMemberCallExpr>(RangeArg->IgnoreParenImpCasts()))
+          ReplaceText = fixit::formatDereference(*ArgExpr, *Result.Context);
+        Diag << FixItHint::CreateReplacement(RangeArg->getSourceRange(),
+                                             ReplaceText);
       } else {
         assert(ReverseDescriptor && "Couldn't find forward argument");
         ArgNode.push_back('R');
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index 1724b9311e57e..e98234191c15e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -11,7 +11,8 @@
 void Positives() {
   std::vector<int> I, J;
   std::vector<std::unique_ptr<int>> K;
-
+  std::vector<int> PointerContainers[2];
+  std::vector<int> *P = PointerContainers;
   // Expect to have no check messages
   std::find(K.begin(), K.end(), nullptr);
 
@@ -27,6 +28,18 @@ void Positives() {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 1);
 
+  std::find(P->cbegin(), P->cend(), 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(*P, 2);
+
+  std::find(P->begin(), P->end(), 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(*P, 3);
+
+  std::find((P + 1)->begin(), (P + 1)->end(), 4);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(*(P + 1), 4);
+
   std::find(std::begin(I), std::end(I), 2);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 2);

>From 3eb10646f05e06a639b73d41fc92865a004f0bd3 Mon Sep 17 00:00:00 2001
From: ZenginU <[email protected]>
Date: Sat, 26 Sep 2026 23:01:15 -0400
Subject: [PATCH 2/2] Add the fix to the ReleaseNotes.md

---
 clang-tools-extra/docs/ReleaseNotes.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.md 
b/clang-tools-extra/docs/ReleaseNotes.md
index 833638a47abc6..52b201dc11d4f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -240,6 +240,10 @@ infrastructure are described first, followed by 
tool-specific sections.
   <clang-tidy/checks/modernize/use-noexcept>` when analyzing malformed template
   code with an unparsed exception specification.
 
+- Improved {doc}`modernize-use-ranges
+  <clang-tidy/checks/modernize/use-ranges>` check by correctly dereferencing
+  raw pointers to containers in fix-its.
+
 - Extend {doc}`modernize-use-nullptr
   <clang-tidy/checks/modernize/use-nullptr>` to turn `decltype(nullptr)` into
   `std::nullptr_t` from `<cstdef>`.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to