1 // ensure that exceptions thrown inside a custom contract violation handler
2 // are not catchable up the call stack when continue mode is off and the
3 // assert fails in a noexcept function
5 // { dg-options "-std=c++2a -fcontracts" }
7 #include <experimental/contract>
9 void handle_contract_violation(const std::experimental::contract_violation &violation) {
10 std::cerr << "custom std::handle_contract_violation called:"
11 << " " << violation.line_number()
12 << " " << violation.file_name()
14 throw -violation.line_number();
23 int main(int, char**) {
27 std::cerr << "synth caught indirect: " << ex << std::endl;
33 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
34 // { dg-output "custom std::handle_contract_violation called: 19 .*/contracts17.C(\n|\r\n|\r)" }
35 // { dg-shouldfail "throwing in noexcept" }