File: contracts-ctor-dtor1.C

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (177 lines) | stat: -rw-r--r-- 6,872 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Tests to ensure that contracts are properly emitted for constructors,
// destructors, and their intersection with templates.
// { dg-do compile }
// { dg-options "-std=c++2a -fcontracts" }

bool pre_{false}, post_{false};
bool delegate_{false};

struct S
{
  S() [[ pre: pre_ ]] [[ post: post_ ]];
  ~S() [[ pre: pre_ ]] [[ post: post_ ]];
};

S::S() { return; }
S::~S() { return; }

struct SInline
{
  SInline() [[ pre: pre_ ]] [[ post: post_ ]] { return; }
  ~SInline() [[ pre: pre_ ]] [[ post: post_ ]] { return; }
};

struct SDelegate0
{
  SDelegate0(int) [[ pre: pre_ ]] [[ post: post_ ]] { return; }
  SDelegate0() : SDelegate0(0) { return; }
  ~SDelegate0() [[ pre: pre_ ]] [[ post: post_ ]] { return; }
};

struct SDelegate1
{
  SDelegate1(int) { return; }
  SDelegate1() [[ pre: pre_ ]] [[ post: post_ ]] : SDelegate1(0) { return; }
  ~SDelegate1() [[ pre: pre_ ]] [[ post: post_ ]] { return; }
};

struct SDelegate2
{
  SDelegate2(int) [[ pre: pre_ ]] [[ post: post_ ]] { return; }
  SDelegate2() [[ pre: pre_ && delegate_ ]] [[ post: post_ && delegate_ ]] : SDelegate2(0) { return; }
  ~SDelegate2() [[ pre: pre_ ]] [[ post: post_ ]] { return; }
};

struct SDelegate3
{
  SDelegate3(int) [[ pre: pre_ ]] [[ post: post_ ]] { return; }
  SDelegate3() [[ pre: pre_ && delegate_ ]] [[ post: post_ && delegate_ ]] : SDelegate3(0) { return; }
  ~SDelegate3() [[ pre: pre_ ]] [[ post: post_ ]] { return; }
};

template<typename T>
struct S1
{
  S1() [[ pre: pre_ ]] [[ post: post_ ]] { }
};

struct S2
{
  template<typename T>
  S2(T) [[ pre: pre_ ]] [[ post: post_ ]] { }
};

template<typename T>
struct S3
{
  template<typename S>
  S3(S) [[ pre: pre_ ]] [[ post: post_ ]] { }
};

struct G0
{
  G0() [[ post: x > 0 ]] {}
  ~G0() [[ pre: x > 0 ]] {}
  int x{-1};
};

struct G1
{
  G1() [[ post: this->x > 0 ]] {}
  ~G1() [[ pre: this->x > 0 ]] {}
  int x{-1};
};

int x{-1};

struct G2
{
  G2() [[ pre: ::x > 0 ]] {}
  ~G2() [[ post: ::x > 0 ]] {}
  int x{1};
};

void test0()
{
  S s;
  SInline si;
  SDelegate0 sd0;
  SDelegate1 sd1;
  SDelegate2 sd2;
  SDelegate3 sd3;
  S1<int> s1_i;
  S1<double> s1_d;
  S2 s2_i{1};
  S2 s2_d{.1};
  S3<int> s3_i_i{1};
  S3<int> s3_i_d{.1};
  S3<double> s3_d_i{1};
  S3<double> s3_d_d{.1};
}

void test1()
{
  G0 g0;
  G1 g1;
  G2 g2;
}

int main(int, char**)
{
  test0();
  test1();
  return 0;
};

// test0
// { dg-output "contract violation in function S::S at .*.C:11 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S::S at .*.C:11 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SInline::SInline at .*.C:20 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SInline::SInline at .*.C:20 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate0::SDelegate0 at .*.C:26 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate0::SDelegate0 at .*.C:26 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate1::SDelegate1 at .*.C:34 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate1::SDelegate1 at .*.C:34 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:41 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:40 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:40 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:41 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:48 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:47 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:47 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:48 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S1<int>::S1 at .*.C:55 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S1<int>::S1 at .*.C:55 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S1<double>::S1 at .*.C:55 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S1<double>::S1 at .*.C:55 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S2::S2<int> at .*.C:61 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S2::S2<int> at .*.C:61 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S2::S2<double> at .*.C:61 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S2::S2<double> at .*.C:61 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<int>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<int>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<int>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<int>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<double>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<double>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<double>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S3<double>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate3::~SDelegate3 at .*.C:49 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate3::~SDelegate3 at .*.C:49 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate2::~SDelegate2 at .*.C:42 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate2::~SDelegate2 at .*.C:42 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate1::~SDelegate1 at .*.C:35 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate1::~SDelegate1 at .*.C:35 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate0::~SDelegate0 at .*.C:28 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SDelegate0::~SDelegate0 at .*.C:28 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SInline::~SInline at .*.C:21 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function SInline::~SInline at .*.C:21 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S::~S at .*.C:12 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function S::~S at .*.C:12 .*(\n|\r\n|\r)" }

// test1
// { dg-output "contract violation in function G0::G0 at .*.C:73 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function G1::G1 at .*.C:80 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function G1::~G1 at .*.C:81 .*(\n|\r\n|\r)" }
// { dg-output "contract violation in function G0::~G0 at .*.C:74 .*(\n|\r\n|\r)" }