1 // ensure that exceptions thrown inside a custom contract violation handler
2 // are not catchable up the call stack when failing in a noexcept function
4 // { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on" }
6 #include <experimental/contract>
8 void handle_contract_violation(const std::experimental::contract_violation &violation) {
9 std::cerr << "custom std::handle_contract_violation called:"
10 << " " << violation.line_number()
11 << " " << violation.file_name()
13 throw -(int)violation.line_number();
27 int main(int, char**) {
32 std::cerr << "synth caught direct: " << ex << std::endl;
38 std::cerr << "synth caught indirect: " << ex << std::endl;
44 std::cerr << "synth caught double indirect: " << ex << std::endl;
47 std::cerr << "end main" << std::endl;
51 // { dg-output "custom std::handle_contract_violation called: 30 .*/contracts15.C(\n|\r\n|\r)" }
52 // { dg-output "synth caught direct: -30(\n|\r\n|\r)" }
53 // { dg-output "custom std::handle_contract_violation called: 18 .*/contracts15.C(\n|\r\n|\r)" }
54 // { dg-output "terminate called after throwing an instance of .int.(\n|\r\n|\r)" }
55 // { dg-shouldfail "throwing in noexcept" }