[clang-tools-extra] [clang-tidy] Add bugprone-smartptr-reset-ambiguous-call check (PR #121291)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 30 04:37:12 PST 2024
================
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - bugprone-smartptr-reset-ambiguous-call
+
+bugprone-smartptr-reset-ambiguous-call
+======================================
+
+Finds potentially erroneous calls to ``reset`` method on
+smart pointers when the pointee type also has a ``reset`` method.
+Having ``reset`` method in both classes makes it easy to accidentally
+make the pointer null when intending to reset the underlying object.
+
+.. code-block:: c++
+
+ struct Resettable {
+ void reset() { /* Own reset logic */ }
+ };
+
+ auto ptr = std::make_unique<Resettable>();
+
+ ptr->reset(); // Calls underlying reset method
+ ptr.reset(); // Makes the pointer null
+
+Both calls are valid C++ code, but the second one might not be
+what the developer intended, as it destroys the pointed-to object
+rather than resetting its state.
+It's easy to make such typo because the difference between ``.`` and ``->`` is really small.
----------------
5chmidti wrote:
`such a typo`
https://github.com/llvm/llvm-project/pull/121291
More information about the cfe-commits
mailing list