[clang-tools-extra] [clang-tidy] readability-redundant-smartptr-get: disable for smart pointers to arrays (PR #141092)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri May 23 08:32:13 PDT 2025


================
@@ -44,7 +44,10 @@ internal::Matcher<Expr> callToGet(const internal::Matcher<Decl> &OnClass) {
 }
 
 internal::Matcher<Decl> knownSmartptr() {
-  return recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr"));
+  return recordDecl(
+      hasAnyName("::std::unique_ptr", "::std::shared_ptr"),
+      unless(anyOf(has(cxxMethodDecl(hasName("operator[]"))),
----------------
kadircet wrote:

i can't comment on the unchanged lines, but this will affect non-dereferencing uses as well (e.g. `foo.get() == nullptr` or `foo.get() ? X : Y`, ...), i think we shouldn't regress those. so can you just change the matchers we feed for those 2 specific cases in `registerMatchersForGetArrowStart`?

i think we should just make sure methoddecl requirements in `QuacksLikeASmartptr` holds also for `std::{unique,shared}_ptr`, rather than looking for absence of `operator[]` (as we're actually not interested in lack of `operator[]` but existence of `operator{*,->}`).

https://github.com/llvm/llvm-project/pull/141092


More information about the cfe-commits mailing list