-
Notifications
You must be signed in to change notification settings - Fork 7
[basic.life] CWG2625 broke dynamic arrays providing storage #415
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
I'd say it should've been There would be a way to circumvent this issue somewhat if only there would exist a way to transparently replace the array immediately prior the deletion. Unfortunately, as per my knowledge, there is none: under the current wording |
IMO the least terrible way is keeping array elements living after Or, perhaps we can just restore the "the object will be or was of a class type" part. |
Even for non-class types (e.g. "int"), we want this rule to apply. The problem here really is the array-delete, where we don't pass a pointer to the entire array, but just a pointer to the first element (because that's how array-delete works). In the initial example, the array actually provides storage, so its lifetime does not end, and array-deleting it is fine. |
Then the intention goes that the following should be undefined? {
int i;
i.~decltype(i)() /* lifetime ended once */;
} /* lifetime ended twice */ It's likely that there are no formal grounds for this to be the case either. You might want to visit this post, @jensmaurer: I've attempted to dissect the problem at length there (the second to last paragraph summarizes the relevance; the discussion there stems from #361 which might turn out to be relevant as well). |
Yes, that's at least my opinion (possibly with the exception of "unsigned char"). |
Some revisions would be needed then, I guess. I would much prefer for such cases not to rely on vague interpretations of [basic.life#4] (personally, I would like it moved to notes altogether while fixing the probable remaining gaps with less... arcane clauses). |
Should we consider striking the whole [basic.life] p6.1? As discussed in #435, a delete-expression generally destroys the pointed-to object, and it's already UB to do this for out-of-lifetime class objects. Although the issue for double destruction of scalar objects is not yet resolved. As a contrived case (not related to dynamic arrays), the delete-expression may call a destroying |
I guess the preferred resolution would be... Change [basic.life] p1.5 as:
Change [intro.object] p3 as (add before the note):
Just keeping array elements living avoids all issues with double destruction. |
Full name of submitter: JMC
Reference (section label): [basic.life]
Link to reflector thread (if any): https://stackoverflow.com/questions/77023929/c23-changes-disallow-using-dynamically-allocated-array-as-storage-provider
Issue description:
CWG2625 did to [basic.life]/6.1:
now consider
Suggested resolution:
Undo CWG2625 resolution. Or, at least, limit the restriction to single-object delete expression.
The text was updated successfully, but these errors were encountered: