<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120908>120908</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Check request: don't use `reset` for a smart pointer to Resetable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
denzor200
</td>
</tr>
</table>
<pre>
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
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVN2u4jYQfhpzMwIZhwS4yEXOYZF62z7AyomHxF3HznrGUPr0lRPYpWdXVaWVkABN5pvvZzKayPYesRblmyhPK514CLE26P8OUUm5aoO51w1RGhFuCIO-ImhIhHFt8GI9GuD7hCAq2YhKiqIRy4_lIxvimDqGBsT-TcgGAOAarIGIhCzUQahjLoFQZ6EaaITaE4SbBxd62wGH5UmgMCIP1vcgVCPUGcT-lEftT6J4-zCz8QZ4QA88WFr43TSB9cTas9WMBhLNWJUkNpl10SRvvyb8PHEUlYRM7aVIg45onkXtKIDuOpxYtw6FOv4oXCcOoEEUJ_iGMuov-HmZI4r3RhSfFgd-lPCH9R1CG3j4D47am6fxSzKikouvlYRsVzBwszyAsZcLRvQMI2pvfS_UO1iG0fYDQ4ugx9b2KSTKhifCbN_4E01rUXx6SU4Uj-DOMGG8hDhS7nxk91wQ63Os7yCU0kIpINZ3Au3sFTPm5gPgE_H5eItdGJHAJ-ey8H9TErL57UUIpThFS2jgEiJomGLoox5HjFlZp50DH3gm-WrWgIB_TdgxZaLZV8vzJqKme-7MyQGlbsjrFDIn_bDpm7k5L-Qbos_Qm5eAsmv5b0Tt3B1o1M5tcshpmgLlF6pFZoxw0_MwO04OxxxXxu-CQdBtuOJPAtn0T-s-2vjLucyr-zT9O-D_iGVl6sIci6NeYb3dF7vDoVS7cjXUUsqu2G7L6nI86O54OZR6p_fmaGSrLtWhXNlaSbXbKqW2VbGT5UYfi-6wP3TGqKrQqhQ7iaO2buPcddyE2K8sUcJ6q-RRHlZOt-hovmZKdU77fs3W3IVS-brFOnet29ST2Elniek7Dlt28x18aStP8D5g9wUifk1ILIoGTPBC7Xl-S15XaNk3GnVkmIL1vKzc77mej8QqRVcPzBPlGGcve8tDajddGIU6ZyKPr_UUw5_YsVDnWR0JdX4IvNbqnwAAAP__Wkm_9A">