[Issue 24010] New: Destructor called before end of scope for tuples

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 22 22:03:17 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24010

          Issue ID: 24010
           Summary: Destructor called before end of scope for tuples
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johanengelen at weka.io

Testcase:
```
alias AliasSeq(TList...) = TList;

import core.stdc.stdio;

int i = 0;
struct A {
    ~this() {
        printf("~this\n");
        i *= 2;
    }
}

void main() {
    {
        AliasSeq!(A, A) params;
        printf("statement\n");
        i = 1;
    }
    printf("%d\n", i);
    assert(i == 4);
}
```

The assertion fails.
Looking at the printout:
```
~this
~this
statement
1
```
you can see that the dtors are called before the statement `i = 1;`, instead of
at the end of the scope.

--


More information about the Digitalmars-d-bugs mailing list