[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
Mon Nov 4 07:21:46 PST 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:

> `has_value` together with `value`

Ahh I see. I was thinking of them separately, but I guess I can see that if `has_value` returns true then the next action will be `value` which probably shouldn't be relied on, so you could say `has_value` shouldn't be relied on either.

> I would've said that this PR should be blocked until the above is handled correctly, but actually, the PR as is, is removing some false-positives by considering the calls to `reset` as resetting the state. So there are no real negatives attached to this PR, that weren't there before, it's only improving the state. The changes outlined above make some negatives positives, which could be done in a follow-up (+issue in case you do not end up implementing it) (in one go would be nicer, of course).

Ah okay. Could we move forward with this PR then? I'll make an issue for this, but I'm not sure when I'll find the time to work on that, and I don't want to block this on that change.

https://github.com/llvm/llvm-project/pull/114255


More information about the cfe-commits mailing list