ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Dtor not called on variable with UDA applied

Open JohanEngelen opened this issue 4 years ago • 0 comments

In the testcase below, the dtor of x is not called when a UDA is applied. DMD and GDC do call the dtor, but LDC does not. The frontend AST indeed does not show x.~this() when the UDA is applied, but magically DMD does call the dtor (correct), and LDC does not (incorrect).

import std.stdio;

struct RAII
{
    int i;
    this(int a) { i = a; }
    ~this() {
        writeln("dtor", i);
    }
}

struct someUDA {}

void foo() {
  @someUDA  // comment out to have the dtor run.
  auto x = RAII(1);
}

void main() {
    foo();
}

JohanEngelen avatar Jan 10 '22 18:01 JohanEngelen