Skip to content

Commit 4215a22

Browse files
committed
Split up base and member destructor referencing
1 parent dd0856a commit 4215a22

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

clang/include/clang/Sema/Sema.h

+1
Original file line numberDiff line numberDiff line change
@@ -5432,6 +5432,7 @@ class Sema final : public SemaBase {
54325432
void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
54335433
CXXRecordDecl *Record);
54345434

5435+
void MarkBaseDestructorReferenced(SourceLocation Loc, CXXRecordDecl *Record);
54355436
void MarkFieldDestructorReferenced(SourceLocation Loc, FieldDecl *Field);
54365437

54375438
/// Mark destructors of virtual bases of this class referenced. In the Itanium

clang/lib/Sema/SemaDeclCXX.cpp

+26-29
Original file line numberDiff line numberDiff line change
@@ -5458,24 +5458,12 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
54585458
if (!Field)
54595459
continue;
54605460

5461-
RecordDecl *Parent = Field->getParent();
5462-
5463-
while (Parent) {
5464-
if (Parent->isUnion()) {
5465-
MarkFieldDestructorReferenced(Location, Field);
5466-
break;
5467-
}
5468-
5469-
if (!Parent->isAnonymousStructOrUnion() || Parent == ClassDecl) {
5470-
break;
5471-
}
5472-
5473-
Parent = cast<RecordDecl>(Parent->getDeclContext());
5474-
}
5461+
MarkFieldDestructorReferenced(Location, Field);
54755462
}
5463+
54765464
// Constructors implicitly reference the base and member
54775465
// destructors.
5478-
MarkBaseAndMemberDestructorsReferenced(Location, Constructor->getParent());
5466+
MarkBaseDestructorReferenced(Location, Constructor->getParent());
54795467
}
54805468

54815469
return HadError;
@@ -5816,24 +5804,13 @@ void Sema::MarkFieldDestructorReferenced(SourceLocation Location,
58165804
DiagnoseUseOfDecl(Dtor, Location);
58175805
}
58185806

5819-
void
5820-
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
5821-
CXXRecordDecl *ClassDecl) {
5807+
void Sema::MarkBaseDestructorReferenced(SourceLocation Location,
5808+
CXXRecordDecl *ClassDecl) {
58225809
// Ignore dependent contexts. Also ignore unions, since their members never
58235810
// have destructors implicitly called.
5824-
if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
5811+
if (ClassDecl->isDependentContext())
58255812
return;
58265813

5827-
// FIXME: all the access-control diagnostics are positioned on the
5828-
// field/base declaration. That's probably good; that said, the
5829-
// user might reasonably want to know why the destructor is being
5830-
// emitted, and we currently don't say.
5831-
5832-
// Non-static data members.
5833-
for (auto *Field : ClassDecl->fields()) {
5834-
MarkFieldDestructorReferenced(Location, Field);
5835-
}
5836-
58375814
// We only potentially invoke the destructors of potentially constructed
58385815
// subobjects.
58395816
bool VisitVirtualBases = !ClassDecl->isAbstract();
@@ -5889,6 +5866,26 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
58895866
&DirectVirtualBases);
58905867
}
58915868

5869+
void Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
5870+
CXXRecordDecl *ClassDecl) {
5871+
// Ignore dependent contexts. Also ignore unions, since their members never
5872+
// have destructors implicitly called.
5873+
if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
5874+
return;
5875+
5876+
// FIXME: all the access-control diagnostics are positioned on the
5877+
// field/base declaration. That's probably good; that said, the
5878+
// user might reasonably want to know why the destructor is being
5879+
// emitted, and we currently don't say.
5880+
5881+
// Non-static data members.
5882+
for (auto *Field : ClassDecl->fields()) {
5883+
MarkFieldDestructorReferenced(Location, Field);
5884+
}
5885+
5886+
MarkBaseDestructorReferenced(Location, ClassDecl);
5887+
}
5888+
58925889
void Sema::MarkVirtualBaseDestructorsReferenced(
58935890
SourceLocation Location, CXXRecordDecl *ClassDecl,
58945891
llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases) {

0 commit comments

Comments
 (0)