[clang] [clang][analyzer] Improved message in uninitialized.Assign at default assignment (PR #208173)

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 13 03:44:35 PDT 2026


================
@@ -73,6 +73,20 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
         }
       }
 
+      if (const auto *MD =
+              dyn_cast<CXXMethodDecl>(C.getStackFrame()->getDecl())) {
+        if ((MD->isCopyAssignmentOperator() ||
+             MD->isMoveAssignmentOperator()) &&
+            MD->isDefaulted() && B->isAssignmentOp()) {
+          OS << "Value assigned to field '"
+             << cast<MemberExpr>(B->getRHS()->IgnoreImpCasts())
+                    ->getMemberDecl()
+                    ->getName()
+             << "' in " << (!MD->isImplicit() ? "default" : "implicit")
+             << " assignment operator is uninitialized";
----------------
balazske wrote:

The expectation was that if an undefined value is assigned inside a generated `operator=`, this must be a `x = other.x` form of expression. There may occur other code like loops but not any arbitrary expression like redundant braces. I added now a check for `MemberExpr` and the LHS is used, so the warning message text remains at least always exact ("value assigned to field").

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


More information about the cfe-commits mailing list