| 1 |
.. title:: clang-tidy - readability-uniqueptr-delete-release |
| 2 |
|
| 3 |
readability-uniqueptr-delete-release |
| 4 |
==================================== |
| 5 |
|
| 6 |
Replace ``delete <unique_ptr>.release()`` with ``<unique_ptr> = nullptr``. |
| 7 |
The latter is shorter, simpler and does not require use of raw pointer APIs. |
| 8 |
|
| 9 |
.. code-block:: c++ |
| 10 |
|
| 11 |
std::unique_ptr<int> P; |
| 12 |
delete P.release(); |
| 13 |
|
| 14 |
// becomes |
| 15 |
|
| 16 |
std::unique_ptr<int> P; |
| 17 |
P = nullptr; |
| 18 |
|
| 19 |
Options |
| 20 |
------- |
| 21 |
|
| 22 |
.. option:: PreferResetCall |
| 23 |
|
| 24 |
If `true`, refactor by calling the reset member function instead of |
| 25 |
assigning to ``nullptr``. Default value is `false`. |
| 26 |
|
| 27 |
.. code-block:: c++ |
| 28 |
|
| 29 |
std::unique_ptr<int> P; |
| 30 |
delete P.release(); |
| 31 |
|
| 32 |
// becomes |
| 33 |
|
| 34 |
std::unique_ptr<int> P; |
| 35 |
P.reset(); |