[clang] [clang][analyzer] Handle explicit-object move assignment (PR #218303)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 17:56:53 PDT 2026


================
@@ -705,6 +713,30 @@ void MoveChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const {
     }
   }
 
+  // Calls to explicit-object member functions are represented as ordinary
+  // function calls because they have no implicit 'this' argument.  Model an
+  // explicit-object assignment here before handling instance calls below.
+  const auto *ExplicitObjectMethod =
+      dyn_cast_or_null<CXXMethodDecl>(Call.getDecl());
+  if (ExplicitObjectMethod &&
+      ExplicitObjectMethod->isExplicitObjectMemberFunction() &&
+      ExplicitObjectMethod->getOverloadedOperator() == OO_Equal) {
+    const MemRegion *ThisRegion = Call.getArgSVal(0).getAsRegion();
+    State = removeFromState(State, ThisRegion);
+
+    if (ExplicitObjectMethod->isCopyAssignmentOperator() ||
+        ExplicitObjectMethod->isMoveAssignmentOperator()) {
+      const MemRegion *ArgRegion = Call.getArgSVal(1).getAsRegion();
+      const CXXRecordDecl *RD = ExplicitObjectMethod->getParent();
+      MisuseKind MK =
+          ExplicitObjectMethod->isMoveAssignmentOperator() ? MK_Move : MK_Copy;
+      modelUse(State, ArgRegion, RD, MK, C);
+      return;
+    }
+    C.addTransition(State);
+    return;
+  }
----------------
haoNoQ wrote:

> I guess because explicit obj calls are not CXXInstanceCalls. The next question is, should it be part of CXXInstanceCalls?

And the next next question is, should the difference between those be erased entirely when constructing the AST, so that we didn't need to update every single C++ tool?

But this ship might have already sailed, and/or there may have been some standar lawyer-y reasons why that's a bad idea.

Yeah I think making it a CXXInstanceCall is the least we can do. Updating every C++ checker sounds tedious, and remembering this cornercase in the future sounds even more tedious.

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


More information about the cfe-commits mailing list