Debian Codegraph @

gcc/testsuite/g++.dg/contracts/contracts-pre2a2.C

raw
1 // basic test to ensure contracts work pre-c++2a
2 // { dg-do run { target c++11 } }
3 // { dg-additional-options "-fcontracts -fcontract-continuation-mode=on" }
4
5 int f(int n)
6 [[ pre: n > 0 ]]
7 [[ post r: r < 0 ]]
8 {
9 [[ assert: n > 0 ]];
10 return -n;
11 }
12
13 int main()
14 {
15 f(-5);
16 return 0;
17 }
18
19 // { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } }
20 // { dg-output "contract violation in function f at .*\\.C:6: .*(\n|\r\n|\r)" }
21 // { dg-output "contract violation in function f at .*\\.C:9: .*(\n|\r\n|\r)" }
22 // { dg-output "contract violation in function f at .*\\.C:7: .*(\n|\r\n|\r)" }
23