[Issue 23107] New: dtor incorrectly skipped
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 13 10:27:46 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23107
Issue ID: 23107
Summary: dtor incorrectly skipped
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: eyal at weka.io
struct Wrapper {
// the bug only reproduces if there's an explicit ctor (in addition to the
dtor):
this(int* _dtors) { this.dtors = _dtors; }
~this() { ++*dtors; }
int* dtors;
alias dtors this;
}
int* explicit(int* dtors) { return Wrapper(dtors).dtors; }
int* implicit(int* dtors) { return Wrapper(dtors); }
unittest {
bool check() {
{
int dtors;
int* foo = explicit(&dtors);
assert(foo == &dtors);
assert(dtors == 1); // <-- assertion fails in CTFE only
}
{
int dtors;
int* foo = implicit(&dtors);
assert(foo == &dtors);
assert(dtors == 1); // <-- assertion fails in both CTFE and runtime
}
return true;
}
assert(check());
// static assert(check()); // <-- uncomment to get CTFE behavior validation
too
}
--
More information about the Digitalmars-d-bugs
mailing list