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
[unique.ptr] Clarify nullptr case in destructor and reset() #2962
[unique.ptr] Clarify nullptr case in destructor and reset() #2962
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This use of "well-formed" is a syntactic requirement, it says the expression must compile. It places no requirements on the value of get()
, and it doesn't make sense to say it only needs to be well-formed for certain values. So this change is wrong.
@jwakely in my proposed change, there's no change to the applicability of "well-formed". The change is to the applicability of "well-defined behavior" in the case where the |
Doh, you're quite right, I misread the diff, sorry. |
Now that I've remembered how to read, I think the "shall not throw exceptions" requirement should only apply to the |
Thanks for the update. It might be easier to use the new specification structure that the standard library clauses are migrating to:
But somebody else is already working on doing that. Whichever structure we use, this is a requirement that says "if this expression isn't well-defined, then it's undefined", which is a tautology. The "shall not throw" part is still useful though. |
I stumbled across this because I was curious as to whether the standard required a null check on the part of the deleter. I think it's still helpful to say that there is no requirement for |
Well, you could add a note (as in "[Note: blah -- end note]") to say that the result of get_deleter() is never invoked with a null pointer value, and thus no requirements are imposed on the deleter for that argument value. |
Were I to specify these destructors in a green field, I'd write simply:
and not bother with explicit requirements. (Note that "no effects" is just as wrong here as virtually every place we use it in the Library: |
@CaseyCarter, I fully agree. However, introducing "Equivalent to" in an editorial issue is usually ... not what we do. @zygoloid? |
Please rebase and fix the conflicts, then force-push. |
In `unique_ptr::~unique_ptr` and `unique_ptr::reset`, the Requires statements are ambiguous about whether `get_deleter()(nullptr)` should have well-defined behaviour. From the Effects statements for both specifications, it's clear that `get_deleter(get())` is not called in the case where the `unique_ptr` contains `nullptr`. This fix makes it clear that `get_deleter(nullptr)` is not required to have well-defined behaviour.
cc17f83
to
43688a9
Compare
Superseded by #4736 |
In
unique_ptr::~unique_ptr
andunique_ptr::reset
, the Requires statements are ambiguous about whetherget_deleter()(nullptr)
should have well-defined behaviour.From the Effects statements for both specifications, it's clear that
get_deleter(get())
is not called in the case where theunique_ptr
containsnullptr
. This fix makes it clear thatget_deleter(nullptr)
is not required to have well-defined behaviour.