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

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Sat May 24 12:01:21 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[]"))),
----------------
vbvictor wrote:

> 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{*,->}`).

+1 here, also, if we introduce such requirements for `knownSmartptr`, maybe it is possible to completely remove `knownSmarptr` from `registerMatchersForGetArrowStart` function so that we don't need to modify `knownSmarptr` at all.

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


More information about the cfe-commits mailing list