File tree 2 files changed +36
-10
lines changed 2 files changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -228,18 +228,20 @@ void IRGenModule::emitClangDecl(const clang::Decl *decl) {
228
228
// Unfortunately, implicitly defined CXXDestructorDecls don't have a real
229
229
// body, so we need to traverse these manually.
230
230
if (auto *dtor = dyn_cast<clang::CXXDestructorDecl>(next)) {
231
- auto cxxRecord = dtor->getParent ();
231
+ if (dtor->isImplicit () || dtor->hasBody ()) {
232
+ auto cxxRecord = dtor->getParent ();
232
233
233
- for (auto field : cxxRecord->fields ()) {
234
- if (auto fieldCxxRecord = field->getType ()->getAsCXXRecordDecl ())
235
- if (auto *fieldDtor = fieldCxxRecord->getDestructor ())
236
- callback (fieldDtor);
237
- }
234
+ for (auto field : cxxRecord->fields ()) {
235
+ if (auto fieldCxxRecord = field->getType ()->getAsCXXRecordDecl ())
236
+ if (auto *fieldDtor = fieldCxxRecord->getDestructor ())
237
+ callback (fieldDtor);
238
+ }
238
239
239
- for (auto base : cxxRecord->bases ()) {
240
- if (auto baseCxxRecord = base.getType ()->getAsCXXRecordDecl ())
241
- if (auto *baseDtor = baseCxxRecord->getDestructor ())
242
- callback (baseDtor);
240
+ for (auto base : cxxRecord->bases ()) {
241
+ if (auto baseCxxRecord = base.getType ()->getAsCXXRecordDecl ())
242
+ if (auto *baseDtor = baseCxxRecord->getDestructor ())
243
+ callback (baseDtor);
244
+ }
243
245
}
244
246
}
245
247
Original file line number Diff line number Diff line change @@ -33,6 +33,29 @@ private:
33
33
BaseClass * pointer;
34
34
} ;
35
35
36
+ class ForwardClassDecl;
37
+
38
+ template < class T>
39
+ class ContainerWithForward {
40
+ public:
41
+ inline ~ ContainerWithForward( ) {
42
+ if ( sizeof ( T) > 0 )
43
+ referencedSymbol ( ) ;
44
+ }
45
+ } ;
46
+
47
+ class ClassWithOutOfLineDestructor {
48
+ public:
49
+ ~ ClassWithOutOfLineDestructor( ) ;
50
+
51
+ ContainerWithForward< ForwardClassDecl> field;
52
+ } ;
53
+
54
+ ClassWithOutOfLineDestructor * getClassWithOutOfLineDestructorValue( ) ;
55
+
56
+ inline void testMethodDestructorFwdDecl ( ) {
57
+ delete getClassWithOutOfLineDestructorValue( ) ;
58
+ }
36
59
37
60
//--- test.swift
38
61
@@ -41,6 +64,7 @@ import DestroyedUsingDelete
41
64
public func test( ) {
42
65
let i = Container ( )
43
66
i. method ( )
67
+ testMethodDestructorFwdDecl ( )
44
68
}
45
69
46
70
// Make sure we reach destructor accessible from `delete` statement.
You can’t perform that action at this time.
0 commit comments