Issue 120908
Summary [clang-tidy] Check request: don't use `reset` for a smart pointer to Resetable
Labels clang-tidy
Assignees
Reporter denzor200
    Assume we have a user-defined type `A`:
```
struct A {
    void reset() { /* A's own logic to reset something */ }
};
```
And then this type was instantiated using `std::unique_ptr` (`std::shared_ptr` also acceptable):
```
auto a = std::make_unique<A>();
```
Since both `std::unique_ptr` and `A` have `reset` method with different meaning, it might be ambiguous to use them:
```
a->reset(); // performs the logic defined in A, "a" stays alive
a.reset();  // "a" becomes nullptr
```

It might be surprised for a programmer to call not the `reset` he expects, and it's easy to make such typo because the difference between `.` and `->` really small.
Suppose a better way to implement the code above:
```
a.get().reset(); // performs the logic defined in A, "a" stays alive
a = nullptr; // "a" becomes nullptr
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to