Skip to content

Commit 2a824d6

Browse files
dkorpelclaude
andcommitted
Fix #22709 - Use of extern(C++) destructor is hidden
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2d17e7c commit 2a824d6

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

compiler/src/dmd/dsymbolsem.d

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4502,10 +4502,20 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
45024502
if (auto cldec = ad.isClassDeclaration())
45034503
{
45044504
assert (cldec.cppDtorVtblIndex == -1); // double-call check already by dd.type
4505-
if (cldec.baseClass && cldec.baseClass.cppDtorVtblIndex != -1)
4505+
// Walk up the base chain: an intermediate class may have no explicit
4506+
// dtor (cppDtorVtblIndex == -1) yet still inherit a dtor vtbl slot.
4507+
// https://github.com/dlang/dmd/issues/22709
4508+
int inheritedDtorVtblIndex = -1;
4509+
for (auto base = cldec.baseClass; base; base = base.baseClass)
4510+
if (base.cppDtorVtblIndex != -1)
4511+
{
4512+
inheritedDtorVtblIndex = base.cppDtorVtblIndex;
4513+
break;
4514+
}
4515+
if (inheritedDtorVtblIndex != -1)
45064516
{
45074517
// override the base virtual
4508-
cldec.cppDtorVtblIndex = cldec.baseClass.cppDtorVtblIndex;
4518+
cldec.cppDtorVtblIndex = inheritedDtorVtblIndex;
45094519
}
45104520
else if (!dd.isFinal())
45114521
{
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://github.com/dlang/dmd/issues/22709
2+
// extern(C++) destructor in base class should not be flagged as hidden
3+
4+
extern(C++):
5+
class A
6+
{
7+
~this();
8+
}
9+
class B : A
10+
{
11+
}
12+
class C : B
13+
{
14+
~this();
15+
}

0 commit comments

Comments
 (0)