diff --git a/compiler/src/dmd/semantic3.d b/compiler/src/dmd/semantic3.d index 8056a0115672..d089262b256e 100644 --- a/compiler/src/dmd/semantic3.d +++ b/compiler/src/dmd/semantic3.d @@ -1556,6 +1556,7 @@ private extern(C++) final class Semantic3Visitor : Visitor */ Identifier id = Identifier.generateId("__o"); auto ts = new ThrowStatement(ctor.loc, new IdentifierExp(ctor.loc, id)); + ts.internalThrow = true; // just rethrows the caught exception auto handler = new CompoundStatement(ctor.loc, ss, ts); auto ctch = new Catch(ctor.loc, getException(), id, handler); diff --git a/compiler/src/dmd/statementsem.d b/compiler/src/dmd/statementsem.d index c74f05f71e61..96af2203d0f7 100644 --- a/compiler/src/dmd/statementsem.d +++ b/compiler/src/dmd/statementsem.d @@ -3644,7 +3644,9 @@ Statement statementSemanticVisit(Statement s, Scope* sc) //printf("ThrowStatement::semantic()\n"); if (throwSemantic(ts.loc, ts.exp, sc)) { - sc.ctorflow.orCSX(CSX.halt); + // internal rethrows shouldn't halt ctor flow + if (!ts.internalThrow) + sc.ctorflow.orCSX(CSX.halt); result = ts; } else diff --git a/compiler/test/runnable/test23401.d b/compiler/test/runnable/test23401.d new file mode 100644 index 000000000000..cb47eb08b56f --- /dev/null +++ b/compiler/test/runnable/test23401.d @@ -0,0 +1,11 @@ +// https://github.com/dlang/dmd/issues/23401 + +struct HasDtor { int x; ~this() {} } +class Base { int marker; this() { marker = 42; } } +class Derived : Base { HasDtor field; this() {} } + +void main() +{ + auto d = new Derived(); + assert(d.marker == 42); +}