xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/readability/uniqueptr-delete-release.rst (revision 6e566bc5523f743bc34a7e26f050f1f2b4d699a8)
1.. title:: clang-tidy - readability-uniqueptr-delete-release
2
3readability-uniqueptr-delete-release
4====================================
5
6Replace ``delete <unique_ptr>.release()`` with ``<unique_ptr> = nullptr``.
7The 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
19Options
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();
36