Skip to content

Commit 409f2e9

Browse files
committed
Address feedback.
1 parent 44a9625 commit 409f2e9

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ Bug Fixes to Attribute Support
402402

403403
Bug Fixes to C++ Support
404404
^^^^^^^^^^^^^^^^^^^^^^^^
405-
406405
- Diagnose binding a reference to ``*nullptr`` during constant evaluation. (#GH48665)
407406
- Suppress ``-Wdeprecated-declarations`` in implicitly generated functions. (#GH147293)
408407
- Fix a crash when deleting a pointer to an incomplete array (#GH150359).
@@ -439,6 +438,8 @@ Bug Fixes to C++ Support
439438
- Correctly deduce return types in ``decltype`` expressions. (#GH160497) (#GH56652) (#GH116319) (#GH161196)
440439
- Fixed a crash in the pre-C++23 warning for attributes before a lambda declarator (#GH161070).
441440
- Fix a crash when attempting to deduce a deduction guide from a non deducible template template parameter. (#130604)
441+
- Fix for clang incorrectly rejecting the default construction of a union with
442+
nontrivial member when another member has an initializer. (#GH81774)
442443

443444
Bug Fixes to AST Handling
444445
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9546,26 +9546,32 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
95469546
CXXMethodDecl *Decl = SMOR.getMethod();
95479547
FieldDecl *Field = Subobj.dyn_cast<FieldDecl*>();
95489548

9549-
int DiagKind = -1;
9549+
enum {
9550+
NotSet = -1,
9551+
NoDecl,
9552+
DeletedDecl,
9553+
MultipleDecl,
9554+
InaccessibleDecl,
9555+
NonTrivialDecl
9556+
} DiagKind = NotSet;
95509557

95519558
if (SMOR.getKind() == Sema::SpecialMemberOverloadResult::NoMemberOrDeleted) {
9552-
if (CSM == Sema::CXXDefaultConstructor && Field &&
9559+
if (CSM == CXXSpecialMemberKind::DefaultConstructor && Field &&
95539560
Field->getParent()->isUnion()) {
95549561
// [class.default.ctor]p2:
95559562
// A defaulted default constructor for class X is defined as deleted if
95569563
// - X is a union that has a variant member with a non-trivial default
95579564
// constructor and no variant member of X has a default member
95589565
// initializer
95599566
const auto *RD = cast<CXXRecordDecl>(Field->getParent());
9560-
if (!RD->hasInClassInitializer())
9561-
DiagKind = !Decl ? 0 : 1;
9562-
} else {
9563-
DiagKind = !Decl ? 0 : 1;
9567+
if (RD->hasInClassInitializer())
9568+
return false;
95649569
}
9570+
DiagKind = !Decl ? NoDecl : DeletedDecl;
95659571
} else if (SMOR.getKind() == Sema::SpecialMemberOverloadResult::Ambiguous)
9566-
DiagKind = 2;
9572+
DiagKind = MultipleDecl;
95679573
else if (!isAccessible(Subobj, Decl))
9568-
DiagKind = 3;
9574+
DiagKind = InaccessibleDecl;
95699575
else if (!IsDtorCallInCtor && Field && Field->getParent()->isUnion() &&
95709576
!Decl->isTrivial()) {
95719577
// A member of a union must have a trivial corresponding special member.
@@ -9581,13 +9587,13 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
95819587
// initializer
95829588
const auto *RD = cast<CXXRecordDecl>(Field->getParent());
95839589
if (!RD->hasInClassInitializer())
9584-
DiagKind = 4;
9590+
DiagKind = NonTrivialDecl;
95859591
} else {
9586-
DiagKind = 4;
9592+
DiagKind = NonTrivialDecl;
95879593
}
95889594
}
95899595

9590-
if (DiagKind == -1)
9596+
if (DiagKind == NotSet)
95919597
return false;
95929598

95939599
if (Diagnose) {
@@ -9605,9 +9611,9 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
96059611
<< /*IsObjCPtr*/ false;
96069612
}
96079613

9608-
if (DiagKind == 1)
9614+
if (DiagKind == DeletedDecl)
96099615
S.NoteDeletedFunction(Decl);
9610-
// FIXME: Explain inaccessibility if DiagKind == 3.
9616+
// FIXME: Explain inaccessibility if DiagKind == InaccessibleDecl.
96119617
}
96129618

96139619
return true;

0 commit comments

Comments
 (0)