[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 2 01:18:02 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())) {
----------------
higher-performance wrote:
Oh wow, nice catch... the C++23 members definitely weren't on my mind; this seems kind of ugly. `std::optional::has_value` seems OK (it's no different than `operator==(std::unique_ptr, std::nullptr_t)`, both of which are OK as they don't actually access the moved-from value), but the monadic operations definitely can be problematic...
But then again, it seems(?) the fact that we don't warn on `operator==` is just an accident caused it being a non-member, not intentional?
I guess, in theory, what we need to do here is to distinguish the different methods, but I don't really have the bandwidth to try to figure out how to implement that...
Barring that, a blanket rule should either allow ~all members, or prohibit ~all members.
I'm kind of torn here. I'd much rather prioritize C++17 over C++23, since I expect `reset` to be used much more, but the monadic operators might eventually become commonplace too.
Ideas?
https://github.com/llvm/llvm-project/pull/114255
More information about the cfe-commits
mailing list