ipa-cp: Perform operations in the appropriate types (PR 118097)
[gcc.git] / gcc / testsuite / g++.dg / contracts / contracts17.C
blob2a8f65a9979ea2377b78cb72ea236868d7d9d824
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
4 // { dg-do run }
5 // { dg-options "-std=c++2a -fcontracts" }
6 #include <iostream>
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()
13     << std::endl;
14   throw -violation.line_number();
17 int fun() noexcept {
18   int x = 0;
19   [[ assert: x < 0 ]];
20   return 0;
23 int main(int, char**) {
24   try {
25     fun();
26   } catch(int &ex) {
27     std::cerr << "synth caught indirect: " << ex << std::endl;
28   }
30   return 0;
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" }