[clang] [Clang][Sema] Fix incorrect rejection default construction of union with nontrivial member (PR #82407)
Mital Ashok via cfe-commits
cfe-commits at lists.llvm.org
Wed May 1 11:13:32 PDT 2024
================
@@ -9442,9 +9442,21 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
int DiagKind = -1;
- if (SMOR.getKind() == Sema::SpecialMemberOverloadResult::NoMemberOrDeleted)
- DiagKind = !Decl ? 0 : 1;
- else if (SMOR.getKind() == Sema::SpecialMemberOverloadResult::Ambiguous)
+ if (SMOR.getKind() == Sema::SpecialMemberOverloadResult::NoMemberOrDeleted) {
+ if (CSM == Sema::CXXDefaultConstructor && Field &&
+ Field->getParent()->isUnion()) {
+ // [class.default.ctor]p2:
+ // A defaulted default constructor for class X is defined as deleted if
+ // - X is a union that has a variant member with a non-trivial default
+ // constructor and no variant member of X has a default member
+ // initializer
+ const auto *RD = cast<CXXRecordDecl>(Field->getParent());
+ if (!RD->hasInClassInitializer())
+ DiagKind = !Decl ? 0 : 1;
----------------
MitalAshok wrote:
You can refactor it like this: https://github.com/MitalAshok/llvm-project/commit/a119d89788c2c642b5a13ea00b2ea649b04a418e and I would suggest changing to an enum for readability: https://github.com/MitalAshok/llvm-project/commit/38ca82e1a55012e7d37fd8c6d049d1f00bb50835 (This can then be extracted out into a static function that returns the enum and each `DiagKind = ...` can turn into `return ...`, and the `if`/`else if` ladder can be dismantled)
https://github.com/llvm/llvm-project/pull/82407
More information about the cfe-commits
mailing list