[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 9 05:30:06 PST 2024
================
@@ -196,10 +196,9 @@ Any occurrence of the moved variable that is not a reinitialization (see below)
is considered to be a use.
An exception to this are objects of type ``std::unique_ptr``,
-``std::shared_ptr`` and ``std::weak_ptr``, which have defined move behavior
-(objects of these classes are guaranteed to be empty after they have been moved
-from). Therefore, an object of these classes will only be considered to be used
-if it is dereferenced, i.e. if ``operator*``, ``operator->`` or ``operator[]``
+``std::shared_ptr``, ``std::weak_ptr``, ``std::optional``, and ``std::any``.
+An object of these classes will only be considered to be used if it is
+dereferenced, i.e. if ``operator*``, ``operator->`` or ``operator[]``
----------------
5chmidti wrote:
+- on this. Maybe rewrite this to
> An exception to this are objects of type ``std::unique_ptr``,
``std::shared_ptr``, ``std::weak_ptr``, ``std::optional``, and ``std::any``, which can be reinitialized via ``reset``.
For smart pointers specifically, the moved-from objects have a well-defined state of being ``nullptr``s, and only
``operator*``, ``operator->`` and ``operator[]`` are considered bad accesses as they would be dereferencing a ``nullptr``.
https://github.com/llvm/llvm-project/pull/114255
More information about the cfe-commits
mailing list