| 1 |
// ensure that passing asserts do not affect constexpr functions |
| 2 |
// ensure that failing asserts generate an error at runtime in constexpr funcs |
| 3 |
// { dg-do run } |
| 4 |
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on" } |
| 5 |
|
| 6 |
constexpr int wfun(int a) { |
| 7 |
[[assert: a > 0]]; |
| 8 |
return a; |
| 9 |
} |
| 10 |
|
| 11 |
constexpr int ffun(int a) { |
| 12 |
[[assert: a > 0]]; |
| 13 |
return a; |
| 14 |
} |
| 15 |
|
| 16 |
template<typename T> |
| 17 |
constexpr int tfun(T a) { |
| 18 |
[[assert: a > 0]]; |
| 19 |
return a; |
| 20 |
} |
| 21 |
|
| 22 |
template<typename T> |
| 23 |
constexpr int wtfun(T a) { |
| 24 |
[[assert: a > 0]]; |
| 25 |
return a; |
| 26 |
} |
| 27 |
|
| 28 |
template<typename T> |
| 29 |
constexpr int ftfun(T a) { |
| 30 |
[[assert: a > 0]]; |
| 31 |
return a; |
| 32 |
} |
| 33 |
|
| 34 |
constexpr int explicitfn(int a) { |
| 35 |
[[assert ignore: a > 0]]; |
| 36 |
[[assert check_maybe_continue: a > 0]]; |
| 37 |
return a; |
| 38 |
} |
| 39 |
|
| 40 |
int main(int, char **) { |
| 41 |
int a = wfun(10); |
| 42 |
int b = ffun(-10); |
| 43 |
int c = wtfun(10); |
| 44 |
int d = ftfun(-10); |
| 45 |
|
| 46 |
int e = explicitfn(-10); |
| 47 |
|
| 48 |
int z = ftfun(-10.0); |
| 49 |
|
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
// { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } } |
| 54 |
// { dg-output "contract violation in function ffun at .*.C:12: .*(\n|\r\n|\r)" } |
| 55 |
// { dg-output "contract violation in function ftfun<int> at .*.C:30: .*(\n|\r\n|\r)" } |
| 56 |
// { dg-output "contract violation in function explicitfn at .*.C:36: .*(\n|\r\n|\r)" } |
| 57 |
// { dg-output "contract violation in function ftfun<double> at .*.C:30: .*(\n|\r\n|\r)" } |
| 58 |
|