-
Notifications
You must be signed in to change notification settings - Fork 7
[basic.life] It is unclear whether destroying an already destroyed scalar object is undefined behavior #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you are referring to the (second) destruction happening automatically for the materialized temporary, it's an explicit issue only for the objects with non-trivial destructors. I'd say this is no different from a more simplified example: {
int i;
i.~decltype(i)();
} The above code is fine, since no non-trivial destructor for |
Yes. I think the status quo is that double destruction of However, it seems to me that [basic.life] p9 is nearly redundant, since [class.dtor] p18 covers almost all (if not all) of such cases. And [class.dtor] p18 states that UB happens even if the destructor is trivial - but pseudo-destructors are not covered. |
Moreover, I'd say [class.dtor#18] itself is redundant in a normative sense. Basically, there are two substatements:
Already stated in [basic.life#1.4].
Already stated in [basic.life#6.2]/[basic.life#7.2], since destructors constitute non-static member functions. |
This definitely seems unclear to me.
|
For what it's worth, in the context of P0593 I think the most logical thing would be to say that it's UB to destroy an out of lifetime object |
[diff.cpp17.basic]/1 also suggests that P0593 intended for this to be UB, but perhaps more wording cleanup is necessary to get us there. |
Full name of submitter (unless configured in github; will be published with the issue): Géry Ogam (cplusplus/draft#4944)
Reference (section label): [basic.life], [basic.start.term], [expr.prim.id.dtor], [expr.delete]
Link to reflector thread (if any):
Issue description:
P0593R6 made pseudo-destructor calls end lifetime of scalar objects. However, currently there lacks wording indicating that destroying an already destroyed scalar object is undefined behavior, which is inconsistent with class objects.
Currently, implementations tend to accept such double destruction in constant evaluation (Godbolt link). Note that Clang is inconsistent with itself, which seems to be a bug.
On the other hand, it is arguably better to keep and clarify the status quo, which avoids inceasing UB.
Suggested resolution:
The changes in cplusplus/draft#4953, if it is intented to make such double destruction undefined.
The text was updated successfully, but these errors were encountered: