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

[dcl.attr.contract.check]p6 user-provided and throwing violation handler #2340

Closed
Rakete1111 opened this issue Sep 24, 2018 · 1 comment
Closed
Assignees

Comments

@Rakete1111
Copy link
Contributor

[dcl.attr.contract.check]p6:

If a user-provided violation handler exits by throwing an exception and a contract is violated on a call to a function with a non-throwing exception specification, then the behavior is as if the exception escaped the function body.

There is no definition of the term "user-provided violation handler". The term is unnecessary either way, a violation handler is always provided by the implementation, and so always "user-provided".

Additionally, why does it mention functions with non-throwing exception specification explicitly? What happens if a violation handler throws for a function with a throwing exception specifications?

@jensmaurer
Copy link
Member

jensmaurer commented Sep 24, 2018

I agree with the concern about "user-provided" violation handler being undefined. Let's remove "user-provided".
Regarding your other concern: p5 encourages implementations to report the caller site as the source location of a precondition violation. The model here is that a precondition violation is a fault of the caller, not the callee, and therefore should be signalled in the caller. However, this model is, at face value, inconsistent with the expectation that a call to a non-throwing function never actually yields an exception. Therefore, the additional sentence ensures that for such a function, no exception escapes by placing the point-of-throw for the violation handler's exception into the body of the called function (which is "wrapped" by the noexcept on the function declaration and yields std::terminate).
These concerns don't apply for calls to functions with throwing exception specifications, so the exception thrown by the violation handler will happily bubble up the stack. (Whether the exception originated from calling the violation handler just before the call to the function with the violated precondition, or just after transferring control to it, is unobservable except for the source location, whose contents was made implementation-defined for exactly that reason.)

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

No branches or pull requests

2 participants