[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 24 03:13:41 PST 2025


vbvictor wrote:

Thank you everyone for the feedback!

@PiotrZSL I tried using TK_IgnoreUnlessSpelledInSource with `cxxDependentScopeMemberExpr` ast-matcher but failed to write a working matcher case with nested template parameters:
```cpp

template <typename T>
void TemplatePositiveTest() {
  std::unique_ptr<T> u_ptr;

  u_ptr.reset();
  u_ptr->reset();
}

void instantiate() {
  TemplatePositiveTest<std::unique_ptr<int>>();
}
```

As for now, I'm thinking about leaving it as is and make an NFC change in the future when I get more familiar with matchers.
Apart from TK_IgnoreUnlessSpelledInSource I fixed your comments.

@5chmidti I fixed all your comments and added better _warning_ and _note_ messages:

```cpp
  s.reset(); // warning: be explicit when calling 'reset()' on a smart pointer with a pointee that has a 'reset()' method
             // note: assign the pointer to 'nullptr'
  s->reset(); // warning: be explicit when calling 'reset()' on a pointee of a smart pointer
              // note: use dereference to call 'reset' method of the pointee
```

@EugeneZelenko Fixed all pr comments.

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


More information about the cfe-commits mailing list