[clang-tools-extra] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 13 11:18:36 PDT 2024


https://github.com/akshaykumars614 created https://github.com/llvm/llvm-project/pull/98757

added a check to remove '->' if exists

>From 283ec53fe19f0008c3c04210ea5c9b20c3d9781c Mon Sep 17 00:00:00 2001
From: akshaykumars614 <akshaykumars614 at gmail.com>
Date: Sat, 13 Jul 2024 14:14:53 -0400
Subject: [PATCH] clang-tidy: readability-redundant-smartptr-get does not
 remove -> (#97964)

added a check to remove '->' if exists
---
 .../clang-tidy/readability/RedundantSmartptrGetCheck.cpp      | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index 8837ac16e8828..be52af77ae0a5 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -164,6 +164,10 @@ void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) {
   StringRef SmartptrText = Lexer::getSourceText(
       CharSourceRange::getTokenRange(Smartptr->getSourceRange()),
       *Result.SourceManager, getLangOpts());
+  // Check if the last two characters are "->" and remove them
+  if (SmartptrText.ends_with("->")) {
+    SmartptrText = SmartptrText.drop_back(2);
+  }
   // Replace foo->get() with *foo, and foo.get() with foo.
   std::string Replacement = Twine(IsPtrToPtr ? "*" : "", SmartptrText).str();
   diag(GetCall->getBeginLoc(), "redundant get() call on smart pointer")



More information about the cfe-commits mailing list