Specify that the struct invariant may be violated when the destructor is called#2410
Conversation
|
Thanks for your pull request and interest in making D better, @FeepingCreature! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
3261b36 to
a1ff8cc
Compare
|
The deeper reasoning behind this is that since we allow |
|
I think this should be done EVEN if there wasn't the case with |
… is called, because the struct may be in its T.init state. This is necessary since there is no way to avoid destroying a struct variable.
a1ff8cc to
b2f95ba
Compare
|
Are you sure this commit is still correct! The diff looks weird. edit: Please at least make it a 72h merge so people can look it over again? It's been ages, and Nullable - the reason I pushed this - doesn't even trigger the destructor anymore. edit: Note that the "disable struct destructor" commit that I pushed above did not get merged! edit: Thanks. |
|
It looks fine to me. Done. Ideally the compiler should insert a unittest to make sure that the destructor hanles the case in |
|
To copypaste the reasoning from the In case it was unclear, this is a really common pattern in our codebase. And with existing semantics, My plan for this was to disable I ended up closing that PR in the end because the horrible |
|
... so ah, 3 days later ... |
|
Should this be merged or closed? |
|
Yeah, this can be removed. The change in question was never implemented, and the |
|
Thanks. |
Specify that the struct invariant may be violated when the destructor is called, because the struct may be in its T.init state.
See also Issue #19065, PR #19037.
Note that
moveEmplacealready implicitly assumes that this is the case! Otherwise, there'd be little sense in it resetting its source to T.init if it has an elaborate destructor.The underlying problem is that struct destructors are the one struct lifetime method that is always, unavoidably called by the compiler and cannot be bypassed. (this() can be bypassed with T.init, this(this) can be bypassed with moveEmplace.)