[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
Fri Nov 1 18:01:47 PDT 2024
================
@@ -279,7 +281,7 @@ void UseAfterMoveFinder::getDeclRefs(
if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) {
// Ignore uses of a standard smart pointer that don't dereference the
// pointer.
- if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) {
+ if (Operator || !isStandardResettableOwner(DeclRef->getDecl())) {
----------------
5chmidti wrote:
I think the check should actually not be ignoring additional operations for `optional` and `any`.
E.g., `optional::has_value` or `optional::and_then` could be problematic.
For smart pointers, their state is well-defined and allows using the object with those other member functions. But in the case of `std::optional` and `std::any`, this is not the case and additional members need to be considered unsafe. E.g., if we move from an `optional` that had a value, then calling `and_then` on that optional would be considered safe right now, but it is unsafe from what I can tell (e.g., https://timsong-cpp.github.io/cppwp/n4861/optional#ctor-9).
https://github.com/llvm/llvm-project/pull/114255
More information about the cfe-commits
mailing list