diff --git a/src/dmd/expression.d b/src/dmd/expression.d index fa269fb85b93..4cfdaa052cd5 100644 --- a/src/dmd/expression.d +++ b/src/dmd/expression.d @@ -6527,7 +6527,9 @@ extern (C++) final class CondExp : BinExp if (v.needsScopeDtor()) { - if (!vcond) + // a temporary is created for the condition + // only if it's not an integral exp + if (!vcond && !ce.econd.isIntegerExp()) { vcond = copyToTemp(STC.volatile_, "__cond", ce.econd); vcond.dsymbolSemantic(sc); @@ -6540,7 +6542,7 @@ extern (C++) final class CondExp : BinExp } //printf("\t++v = %s, v.edtor = %s\n", v.toChars(), v.edtor.toChars()); - Expression ve = new VarExp(vcond.loc, vcond); + Expression ve = vcond ? new VarExp(vcond.loc, vcond) : ce.econd; if (isThen) v.edtor = new LogicalExp(v.edtor.loc, TOK.andAnd, ve, v.edtor); else diff --git a/test/compilable/test20415.d b/test/compilable/test20415.d new file mode 100644 index 000000000000..3c68086eb046 --- /dev/null +++ b/test/compilable/test20415.d @@ -0,0 +1,14 @@ +// https://issues.dlang.org/show_bug.cgi?id=20415 +// REQUIRED_ARGS: -c -O + +void t() +{ + auto a = false ? B().p : null; +} + +struct B +{ + void* p; + ~this() {} +} +