| 1 |
// check that contracts can be handled even when exceptions are disabled |
| 2 |
// { dg-do run } |
| 3 |
// { dg-options "-std=c++2a -fcontracts -fno-exceptions " } |
| 4 |
// { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } } |
| 5 |
// { dg-output "contract violation in function f at .* a<5" } |
| 6 |
|
| 7 |
#include <exception> |
| 8 |
#include <cstdlib> |
| 9 |
|
| 10 |
int terminate_called = 0; |
| 11 |
void my_term() |
| 12 |
{ |
| 13 |
std::exit(0); |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
void f(int a) |
| 18 |
[[ pre : a<5 ]] |
| 19 |
{ |
| 20 |
} |
| 21 |
|
| 22 |
int |
| 23 |
main () |
| 24 |
{ |
| 25 |
std::set_terminate (my_term); |
| 26 |
f(3); |
| 27 |
f(10); |
| 28 |
} |