| 1 |
// ensure a default level assert with a failing predicate does not generate an |
| 2 |
// error during runtime when the contracts mode is off |
| 3 |
// { dg-do run } |
| 4 |
// { dg-options "-std=c++2a -fcontracts -fcontract-mode=off" } |
| 5 |
// { dg-output "returning from main" } |
| 6 |
// { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } } |
| 7 |
#include <cstdio> |
| 8 |
|
| 9 |
int constexpr f() |
| 10 |
{ |
| 11 |
constexpr int x = 1; |
| 12 |
[[assert default: x < 0]]; |
| 13 |
return x; |
| 14 |
} |
| 15 |
|
| 16 |
template<typename T> int k() |
| 17 |
{ |
| 18 |
int x = 1; |
| 19 |
[[assert default: x < 0]]; |
| 20 |
return x; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
int main() |
| 25 |
{ |
| 26 |
int x = 1; |
| 27 |
[[assert default: x < 0]]; |
| 28 |
constexpr int x2 = f(); |
| 29 |
int x3 = k<int>(); |
| 30 |
|
| 31 |
printf ("returning from main\n"); |
| 32 |
return 0; |
| 33 |
} |