[clang] [Clang][Sema] Synthesize a memcpy body for defaulted union assignment (PR #206579)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 23 11:58:26 PDT 2026


================
@@ -14980,6 +14988,22 @@ buildMemcpyForAssignmentOp(Sema &S, SourceLocation Loc, QualType T,
       S.Context, To, UO_AddrOf, S.Context.getPointerType(To->getType()),
       VK_PRValue, OK_Ordinary, Loc, false, S.CurFPFeatureOverrides());
 
+  if (SuppressMemaccessWarning) {
+    // An explicit cast to void* survives IgnoreParenImpCasts, so the memaccess
+    // check sees a void pointee and skips the non-trivial-copy warning.
+    QualType ConstVoidPtr =
+        S.Context.getPointerType(S.Context.VoidTy.withConst());
+    ExprResult FromCast = S.BuildCStyleCastExpr(
+        Loc, S.Context.getTrivialTypeSourceInfo(ConstVoidPtr, Loc), Loc, From);
+    ExprResult ToCast = S.BuildCStyleCastExpr(
----------------
cor3ntin wrote:

(`DiagnosticsEngine::setSeverity` may not be the cleanest option but it is... one option - it would be novel though)

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


More information about the cfe-commits mailing list