Debian Codegraph @

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

raw
1 // { dg-do compile }
2 // { dg-options "-std=c++2a -fcontracts" }
3
4 int f1(int n)
5 [[pre: n >= 0]]
6 [[post r: r >= 0]]
7 [[post r: !(r < 0)]]
8 {
9 return n;
10 }
11
12 int f2(int n)
13 [[post: true]]
14 {
15 return 0;
16 }
17
18 int f3(int n)
19 [[post r: r >= n]]
20 {
21 return n + 1;
22 }
23
24 int f4(int n)
25 [[post: x > 0]] // { dg-error "not declared" }
26 {
27 return 0;
28 }
29
30 void f5()
31 [[post: true]]
32 { }
33
34 void f6()
35 [[post r: true]] // { dg-error "function does not return a value" }
36 { }
37
38 int f7(int n)
39 [[post: n > 0]]
40 {
41 return x; // { dg-error "not declared" }
42 }
43
44 void f8(int n)
45 [[post: n > 0]]
46 {
47 return;
48 }
49
50 void f9(int n)
51 [[post: n > 0]]
52 {
53 return n; // { dg-error "return-statement with a value" }
54 }
55
56 int f10(int n)
57 [[post: n > 0]]
58 {
59 return; // { dg-error "return-statement with no value" }
60 }
61
62 void f11()
63 [[post: true]]
64 {
65 constexpr int n = 0;
66 return n; // { dg-error "return-statement with a value" }
67 }
68
69 int f12()
70 [[post: true]]
71 {
72 return; // { dg-error "return-statement with no value" }
73 }
74