On Monday, 9 February 2026 at 20:19:26 UTC, Brother Bill wrote:
The destructor runs too many times. I would expect it to run just once.
What am I doing "wrong"?

I'd suget a simpler example:

```d
extern(C) int rand();

static cnt = 1;

struct S
{
        ~this()
        {
                cnt--;
        }
}

void main()
{
const cond = ((rand() % 8) + 1) != 0; // not foldable but you know it's true
        if (cond)
        {
                S s;
} // scope leave, run S dtor
        assert(cnt == 0);
}
```


Reply via email to