isocpp / isocpp/CppCoreGuidelines
Clarification requested for Expects/Ensures contract violation behavior
@BjarneStroustrup is already working on this.
Since Feb 27, 2020.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
There have been discussions recently in #1512 and microsoft/GSL#831 regarding contract violation behavior. Would the editors mind clarifying the desired behavior for contract violation and updating GSL.assert as necessary?
The confusion stems from a potential contradiction between an Editor's call in issue #1512 and a note in the GSL.Assert section for Expects.
@hsutter's post from #1512:
Editors' call: GSL.assert currently requires Expects to terminate the program if the condition is false. This is intended to mean std::terminate which permits a terminate_handler to do things like log some final information before restarting the process to try again. There is nothing in the Guidelines today about Expects throwing on contract violations.
Clarification: Expects should terminate, not abort, just to be clear.
Note from the Expects section of GSL.Assert:
// Expect in under control of some options (enforcement, error message, alternatives to terminate)
Microsoft's GSL implementation removed the alternative violation behaviors (throwing & unenforced) with PR microsoft/GSL#831. This change also had the side benefit of preventing potential ODR violations from misconfiguring contract violation behaviors.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.