[clang] Mark union member destructors referenced (PR #128866)

Maurice Heumann via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 26 04:13:52 PST 2025


https://github.com/momo5502 created https://github.com/llvm/llvm-project/pull/128866

This could be a fix for #93251

>From 484ff7a53ab700fda30ee90f739bb2573f41c851 Mon Sep 17 00:00:00 2001
From: Maurice Heumann <maurice.heumann at wibu.com>
Date: Wed, 26 Feb 2025 08:37:04 +0100
Subject: [PATCH] Mark union member destructors referenced

---
 clang/lib/Sema/SemaDeclCXX.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 664d48ccbc382..ce7927dedd96b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5764,7 +5764,7 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
                                              CXXRecordDecl *ClassDecl) {
   // Ignore dependent contexts. Also ignore unions, since their members never
   // have destructors implicitly called.
-  if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
+  if (ClassDecl->isDependentContext() /*|| ClassDecl->isUnion()*/)
     return;
 
   // FIXME: all the access-control diagnostics are positioned on the
@@ -5793,8 +5793,10 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
     if (FieldClassDecl->hasIrrelevantDestructor())
       continue;
     // The destructor for an implicit anonymous union member is never invoked.
-    if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
+    if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion()) {
+      MarkBaseAndMemberDestructorsReferenced(Location, FieldClassDecl);
       continue;
+    }
 
     CXXDestructorDecl *Dtor = LookupDestructor(FieldClassDecl);
     // Dtor might still be missing, e.g because it's invalid.



More information about the cfe-commits mailing list