[clang] [Clang] Partial implementation of support for P3074 (trivial unions) (PR #146815)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 11 08:06:30 PDT 2025
================
@@ -9543,6 +9543,45 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
if (DiagKind == -1)
return false;
+ if (S.Context.getLangOpts().CPlusPlus26 && inUnion() &&
+ CSM == CXXSpecialMemberKind::Destructor) {
+ // [class.dtor]/7 In C++26, a destructor for a union X is only deleted under
+ // the additional conditions that:
+
+ // overload resolution to select a constructor to default-initialize an
+ // object of type X either fails or selects a constructor that is either
+ // deleted or not trivial, or
+ // or X has a variant member V of class type M (or possibly
+ // multi-dimensional array thereof) where V has a default member initializer
+ // and M has a destructor that is non-trivial,
+
+ RecordDecl *Parent = Field->getParent();
+ while (Parent &&
+ (Parent->isAnonymousStructOrUnion() ||
+ (Parent->isUnion() && Parent->getIdentifier() == nullptr))) {
+ if (auto RD = dyn_cast_or_null<RecordDecl>(Parent->getParent()))
+ Parent = RD;
+ else
+ break;
+ }
+
+ auto ParentDecl = dyn_cast<CXXRecordDecl>(Parent);
----------------
Sirraide wrote:
```suggestion
auto ParentDecl = cast<CXXRecordDecl>(Parent);
```
https://github.com/llvm/llvm-project/pull/146815
More information about the cfe-commits
mailing list