| 1 |
// test that free functions can be redeclared with contracts without affecting |
| 2 |
// normal default parm handling |
| 3 |
// { dg-do run } |
| 4 |
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on" } |
| 5 |
#include <cstdio> |
| 6 |
|
| 7 |
int f(int a, int, int c = 10); |
| 8 |
int f(int a, int b = 11, int); |
| 9 |
int f(int a, int b, int c) |
| 10 |
[[ pre: a < 0 ]] |
| 11 |
[[ pre: b < 0 ]] |
| 12 |
[[ pre: c < 0 ]]; |
| 13 |
|
| 14 |
int f(int, int, int); |
| 15 |
|
| 16 |
int f(int a, int b, int c) |
| 17 |
{ |
| 18 |
printf("f: a: %d, b: %d, c: %d\n", a, b, c); |
| 19 |
return a * b - c; |
| 20 |
} |
| 21 |
|
| 22 |
int f(int a = 12, int, int); |
| 23 |
|
| 24 |
int main(int, char **) |
| 25 |
{ |
| 26 |
f(1,1,1); |
| 27 |
printf("=====\n"); |
| 28 |
f(1,1); |
| 29 |
printf("=====\n"); |
| 30 |
f(1); |
| 31 |
printf("=====\n"); |
| 32 |
f(); |
| 33 |
printf("=====\n"); |
| 34 |
} |
| 35 |
|
| 36 |
// { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } } |
| 37 |
// { dg-output "contract violation in function f at .*.C:10: .*(\n|\r\n|\r)" } |
| 38 |
// { dg-output "contract violation in function f at .*.C:11: .*(\n|\r\n|\r)" } |
| 39 |
// { dg-output "contract violation in function f at .*.C:12: .*(\n|\r\n|\r)" } |
| 40 |
// { dg-output "f: a: 1, b: 1, c: 1(\n|\r\n|\r)" } |
| 41 |
// { dg-output "=====(\n|\r\n|\r)" } |
| 42 |
// { dg-output "contract violation in function f at .*.C:10: .*(\n|\r\n|\r)" } |
| 43 |
// { dg-output "contract violation in function f at .*.C:11: .*(\n|\r\n|\r)" } |
| 44 |
// { dg-output "contract violation in function f at .*.C:12: .*(\n|\r\n|\r)" } |
| 45 |
// { dg-output "f: a: 1, b: 1, c: 10(\n|\r\n|\r)" } |
| 46 |
// { dg-output "=====(\n|\r\n|\r)" } |
| 47 |
// { dg-output "contract violation in function f at .*.C:10: .*(\n|\r\n|\r)" } |
| 48 |
// { dg-output "contract violation in function f at .*.C:11: .*(\n|\r\n|\r)" } |
| 49 |
// { dg-output "contract violation in function f at .*.C:12: .*(\n|\r\n|\r)" } |
| 50 |
// { dg-output "f: a: 1, b: 11, c: 10(\n|\r\n|\r)" } |
| 51 |
// { dg-output "=====(\n|\r\n|\r)" } |
| 52 |
// { dg-output "contract violation in function f at .*.C:10: .*(\n|\r\n|\r)" } |
| 53 |
// { dg-output "contract violation in function f at .*.C:11: .*(\n|\r\n|\r)" } |
| 54 |
// { dg-output "contract violation in function f at .*.C:12: .*(\n|\r\n|\r)" } |
| 55 |
// { dg-output "f: a: 12, b: 11, c: 10(\n|\r\n|\r)" } |
| 56 |
// { dg-output "=====(\n|\r\n|\r)" } |
| 57 |
|