| 1 |
// check that contracts work around deduced return types |
| 2 |
// { dg-do run } |
| 3 |
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on" } |
| 4 |
|
| 5 |
auto g0(int a) [[ pre: a < 0 ]] [[ post r: r > 0 ]] |
| 6 |
{ |
| 7 |
return -a * 1.2; |
| 8 |
} |
| 9 |
|
| 10 |
int g1(int m) [[ post r: r == m ]]; |
| 11 |
|
| 12 |
int g1(int n) [[ post s: s == n ]] |
| 13 |
{ |
| 14 |
return -n; |
| 15 |
} |
| 16 |
|
| 17 |
int g2(int z) |
| 18 |
{ |
| 19 |
return -z; |
| 20 |
} |
| 21 |
|
| 22 |
int g3(int z) |
| 23 |
[[ pre: sizeof(decltype(g2(5))) > 4 ]] |
| 24 |
{ |
| 25 |
return -z; |
| 26 |
} |
| 27 |
|
| 28 |
auto g4(int m) [[ post: m ]]; |
| 29 |
|
| 30 |
auto g4(int m) [[ post: m ]] |
| 31 |
{ |
| 32 |
return -m; |
| 33 |
} |
| 34 |
|
| 35 |
auto g5(int m) [[ pre: m ]]; |
| 36 |
|
| 37 |
auto g5(int m) [[ pre: m ]] |
| 38 |
{ |
| 39 |
return -m; |
| 40 |
} |
| 41 |
|
| 42 |
template<typename T> |
| 43 |
auto g6(T t) [[ post r: r == t ]]; |
| 44 |
|
| 45 |
template<typename S> |
| 46 |
auto g6(S s) [[ post q: q == s ]] |
| 47 |
{ |
| 48 |
return -s; |
| 49 |
} |
| 50 |
|
| 51 |
// template<typename T> |
| 52 |
// T g7(T t) [[ post r: r == t ]]; |
| 53 |
|
| 54 |
template<typename S> |
| 55 |
S g7(S s) [[ post q: q == s ]] |
| 56 |
{ |
| 57 |
return -s; |
| 58 |
} |
| 59 |
|
| 60 |
int main(int, char**) { |
| 61 |
g0(5); |
| 62 |
g1(6); |
| 63 |
g2(1); |
| 64 |
g3(1); |
| 65 |
g4(0); |
| 66 |
g5(0); |
| 67 |
g6(5); |
| 68 |
g6(5.5); |
| 69 |
g7(5); |
| 70 |
g7(6.6); |
| 71 |
return 0; |
| 72 |
} |
| 73 |
|
| 74 |
// { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } } |
| 75 |
// { dg-output "contract violation in function g0 at .*.C:5: .*(\n|\r\n|\r)" } |
| 76 |
// { dg-output "contract violation in function g0 at .*.C:5: .*(\n|\r\n|\r)" } |
| 77 |
// { dg-output "contract violation in function g1 at .*.C:12: .*(\n|\r\n|\r)" } |
| 78 |
// { dg-output "contract violation in function g3 at .*.C:23: .*(\n|\r\n|\r)" } |
| 79 |
// { dg-output "contract violation in function g4 at .*.C:30: .*(\n|\r\n|\r)" } |
| 80 |
// { dg-output "contract violation in function g5 at .*.C:37: .*(\n|\r\n|\r)" } |
| 81 |
// { dg-output "contract violation in function g6<int> at .*.C:46: .*(\n|\r\n|\r)" } |
| 82 |
// { dg-output "contract violation in function g6<double> at .*.C:46: .*(\n|\r\n|\r)" } |
| 83 |
// { dg-output "contract violation in function g7<int> at .*.C:55: .*(\n|\r\n|\r)" } |
| 84 |
// { dg-output "contract violation in function g7<double> at .*.C:55: .*(\n|\r\n|\r)" } |
| 85 |
|