Skip to content
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.single] Rephrase destruction #4736

Merged
merged 1 commit into from Feb 22, 2022
Merged

Conversation

jensmaurer
Copy link
Member

Supersedes #2962

@jensmaurer
Copy link
Member Author

@CaseyCarter , @jwakely, what do you think?

@jensmaurer
Copy link
Member Author

@jwakely , ping.

Copy link
Contributor

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems equivalent to me, but makes me wonder why we originally chose UB if the deletion throws vs. simply letting the exception slam into noexcept. @jwakely, does that seem worth a followup library issue?

@jwakely
Copy link
Member

jwakely commented Oct 28, 2021

We already got one: https://cplusplus.github.io/LWG/issue3588 It was promptly closed as NAD. My preference was to just rely on the noexcept but the consensus was strongly NAD.

@jensmaurer
Copy link
Member Author

@tkoeppe , looks like this is ready.

@jwakely
Copy link
Member

jwakely commented Oct 28, 2021

Because it's undefined with the current spec, it's theoretically possible for the implementation to omit the EH code to call terminate() in case the deleter throws, although neither GCC nor Clang provides any way to do that today (I don't know about MSVC). I've mused in GCC's bugzilla about a new attribute that would be something like [[gnu::nothrow]] but would imply a stronger form of noexcept(true) saying no exceptions are possible and terminate won't be called either. We could use that here. It would be UB if something with that attribute throws, which matches the contract here.

@CaseyCarter
Copy link
Contributor

CaseyCarter commented Oct 28, 2021

(Sorry, off-topic.)

Because it's undefined with the current spec, it's theoretically possible for the implementation to omit the EH code to call terminate() in case the deleter throws, although neither GCC nor Clang provides any way to do that today (I don't know about MSVC). I've mused in GCC's bugzilla about a new attribute that would be something like [[gnu::nothrow]] but would imply a stronger form of noexcept(true) saying no exceptions are possible and terminate won't be called either. We could use that here. It would be UB if something with that attribute throws, which matches the contract here.

Ironically enough, we have __declspec(nothrow) with this exact meaning which is notably not used in our implementation of unique_ptr. If someone were to ask us to use it in unique_ptr, we'd almost certainly tell them to make their deleter noexcept/__declspec(nothrow) instead.

@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Feb 21, 2022
@jensmaurer jensmaurer removed the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Feb 21, 2022
@tkoeppe tkoeppe merged commit 0c53bea into cplusplus:main Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants