Skip to content

Commit d95c274

Browse files
committed
Split up base and member destructor referencing
1 parent bb4091d commit d95c274

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
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 MarkBaseDestructorsReferenced(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

+29-33
Original file line numberDiff line numberDiff line change
@@ -5452,29 +5452,18 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
54525452

54535453
SourceLocation Location = Constructor->getLocation();
54545454

5455+
// Constructors implicitly reference the base and member
5456+
// destructors.
5457+
54555458
for (CXXCtorInitializer *Initializer : Info.AllToInit) {
54565459
FieldDecl *Field = Initializer->getAnyMember();
54575460
if (!Field)
54585461
continue;
54595462

5460-
RecordDecl *Parent = Field->getParent();
5461-
5462-
while (Parent) {
5463-
if (Parent->isUnion()) {
5464-
MarkFieldDestructorReferenced(Location, Field);
5465-
break;
5466-
}
5467-
5468-
if (!Parent->isAnonymousStructOrUnion() || Parent == ClassDecl) {
5469-
break;
5470-
}
5471-
5472-
Parent = cast<RecordDecl>(Parent->getDeclContext());
5473-
}
5463+
MarkFieldDestructorReferenced(Location, Field);
54745464
}
5475-
// Constructors implicitly reference the base and member
5476-
// destructors.
5477-
MarkBaseAndMemberDestructorsReferenced(Location, Constructor->getParent());
5465+
5466+
MarkBaseDestructorsReferenced(Location, Constructor->getParent());
54785467
}
54795468

54805469
return HadError;
@@ -5815,24 +5804,11 @@ void Sema::MarkFieldDestructorReferenced(SourceLocation Location,
58155804
DiagnoseUseOfDecl(Dtor, Location);
58165805
}
58175806

5818-
void
5819-
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
5820-
CXXRecordDecl *ClassDecl) {
5821-
// Ignore dependent contexts. Also ignore unions, since their members never
5822-
// have destructors implicitly called.
5823-
if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
5807+
void Sema::MarkBaseDestructorsReferenced(SourceLocation Location,
5808+
CXXRecordDecl *ClassDecl) {
5809+
if (ClassDecl->isDependentContext())
58245810
return;
58255811

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

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

0 commit comments

Comments
 (0)