Skip to content

Commit 8159a4b

Browse files
committed
amending the tests
1 parent 2579569 commit 8159a4b

File tree

3 files changed

+517
-0
lines changed

3 files changed

+517
-0
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// { dg-do run }
2+
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=off -fcontracts-nonattr -fcontracts-nonattr-inheritance-mode=Ville -Wsuggest-explicit-contract" }
3+
#include <cassert>
4+
5+
/*missing bits :
6+
* - virtual destructor
7+
* - virtual constructors
8+
*/
9+
10+
bool test(int i){ return true;}
11+
12+
namespace T1{
13+
struct Base
14+
{
15+
virtual void f1(int i) pre (test(i)){};
16+
virtual void f2(int i) pre (test(i)){};
17+
virtual int f3(const int i) post (test(i)){ return i;};
18+
virtual void f4(const int i) post (test(i)){};
19+
virtual void f5() {};
20+
21+
};
22+
23+
struct Child : Base
24+
{
25+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
26+
virtual void f2(int i) pre (test(i)){}
27+
virtual int f3(const int i) {return i;};// { dg-warning "Function implicitly inherits a contract" }
28+
void f4(int i){}; // { dg-warning "Function implicitly inherits a contract" }
29+
virtual void f5(int i) {};
30+
virtual void f6(int i) {};
31+
32+
};
33+
34+
struct GChild : Child
35+
{
36+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
37+
virtual void f2(int i) pre (test(i)){}
38+
//virtual int f3(int i) not defined
39+
void f4(bool b){};
40+
virtual void f5(int i) {};
41+
42+
};
43+
44+
struct GGChild : GChild
45+
{
46+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
47+
virtual void f2(int i) pre (test(i)){}
48+
virtual int f3(const int i) { return i; }
49+
void f4(int i){};
50+
virtual void f5(int i) {};
51+
52+
};
53+
}; //namespace T1
54+
55+
// template base
56+
namespace T2{
57+
template<typename T>
58+
struct Base
59+
{
60+
virtual void f1(int i) pre (test(i)){};
61+
virtual void f2(int i) pre (test(i)){};
62+
virtual int f3(const int i) post (r: test(r)){ return i;};
63+
virtual void f4(const int i) post (test(i)){};
64+
virtual void f5(int i) {};
65+
virtual void f6(int i) {};
66+
67+
};
68+
69+
70+
struct Child : Base<int>
71+
{
72+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
73+
virtual void f2(int i) pre (test(i)){}
74+
virtual int f3(int i) {return i;};// { dg-warning "Function implicitly inherits a contract" }
75+
void f4(int i){};
76+
virtual void f5(int i) {};
77+
virtual void f6(int i) {};
78+
79+
};
80+
81+
struct GChild : Child
82+
{
83+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
84+
virtual void f2(int i) pre (test(i)){}
85+
//virtual int f3(int i) not defined
86+
void f4(int i){};
87+
virtual void f5(int i) {};
88+
89+
};
90+
91+
struct GGChild : GChild
92+
{
93+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
94+
virtual void f2(int i) pre (test(i)){}
95+
virtual int f3(int i) { return i; }
96+
void f4(int i){};
97+
virtual void f5(int i) {};
98+
99+
};
100+
101+
}; //namespace T2
102+
103+
104+
// template base
105+
namespace T3{
106+
template<typename T>
107+
struct BaseT
108+
{
109+
virtual void f1(int i) pre (test(i)){};
110+
virtual void f2(int i) pre (test(i)){};
111+
virtual int f3(int i) post (r: test(r)){ return i;};
112+
virtual void f4(int i) post (test(i)){};
113+
virtual void f5(int i) {};
114+
virtual void f6(int i) {};
115+
116+
117+
};
118+
119+
struct Child2 : virtual Base<int>
120+
{
121+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
122+
virtual void f2(int i) pre (test(i)){}
123+
virtual int f3(int i) {return i;};// { dg-warning "Function implicitly inherits a contract" }
124+
void f4(int i){};
125+
virtual void f5(int i) {};
126+
virtual void f6(int i) {};
127+
128+
virtual ~Child2() {}// { dg-warning "Function implicitly inherits a contract" }
129+
};
130+
131+
struct GChild2 : Child2
132+
{
133+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
134+
virtual void f2(int i) pre (test(i)){}
135+
//virtual int f3(int i) not defined
136+
void f4(int i){};
137+
virtual void f5(int i) {};
138+
139+
virtual ~Child2() {}// { dg-warning "Function implicitly inherits a contract" }
140+
};
141+
142+
struct GGChild2 : GChild2
143+
{
144+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
145+
virtual void f2(int i) pre (test(i)){}
146+
virtual int f3(int i) { return i; }
147+
void f4(int i){};
148+
virtual void f5(int i) {};
149+
150+
virtual ~Child2() {}// { dg-warning "Function implicitly inherits a contract" }
151+
};
152+
153+
}; //namespace T2
154+
155+
template<typename T>
156+
struct Child3 : Base<T>
157+
{
158+
virtual void f1(int i) {}; // { dg-warning "Function implicitly inherits a contract" }
159+
virtual void f2(int i) pre (test(i)){}
160+
virtual int f3(int i) pre (test(i)){};
161+
void f4(int i){};
162+
virtual void f5(int i) {};
163+
164+
virtual ~Child3() {}// { dg-warning "Function implicitly inherits a contract" }
165+
};
166+
167+
*/
168+
169+
int main(int, char**)
170+
{
171+
172+
{
173+
T1::Base b;
174+
T1::Child c;
175+
T1::GChild gc;
176+
T1::GGChild gc;
177+
}
178+
{
179+
T2::Base b;
180+
T2::Child c;
181+
T2::GChild gc;
182+
T2::GGChild gc;
183+
}
184+
{
185+
T3::Base b;
186+
T3::Child c;
187+
T3::GChild gc;
188+
T3::GGChild gc;
189+
}
190+
191+
192+
return 0;
193+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// { dg-do run }
2+
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=off -fcontracts-nonattr -fcontracts-nonattr-inheritance-mode=P3653 " }
3+
#include <cassert>
4+
5+
struct contract{
6+
int checked = 0;
7+
};
8+
9+
10+
contract a,b,c;
11+
12+
bool checkA(){
13+
a.checked++;
14+
return true;
15+
}
16+
17+
bool checkB(){
18+
b.checked++;
19+
return true;
20+
}
21+
22+
bool checkC(){
23+
c.checked++;
24+
return true;
25+
}
26+
27+
void clear_checks(){
28+
a.checked = b.checked = c.checked = 0;
29+
30+
}
31+
32+
struct Base
33+
{
34+
virtual void f() pre (checkA()){};
35+
};
36+
37+
38+
struct Child0 : virtual Base
39+
{
40+
virtual void f() {}; // inherits checkA
41+
};
42+
43+
struct Child1 : virtual Base
44+
{
45+
virtual void f() pre (checkB()){};
46+
};
47+
48+
struct Child2 : virtual Base
49+
{
50+
virtual void f() pre (checkC()){};
51+
};
52+
53+
54+
struct GChild0 : Child0
55+
{
56+
virtual void f() {}; // inherits checkA
57+
};
58+
59+
60+
struct GChild1 : Child0, Child1
61+
{
62+
virtual void f() pre (checkC()){};
63+
};
64+
65+
struct GChild2 : Child0, Child1
66+
{
67+
virtual void f() {}; //inherits checkA and checkB
68+
};
69+
70+
71+
struct GChild3 : Child2, Child1
72+
{
73+
virtual void f() {}; //inherits checkC and checkB
74+
};
75+
76+
77+
78+
void fooBase(Base* b)
79+
{
80+
b->f();
81+
}
82+
83+
int main(int, char**)
84+
{
85+
Base b0;
86+
Child0 c0;
87+
Child1 c1;
88+
GChild0 g0;
89+
GChild1 g1;
90+
GChild2 g2;
91+
GChild3 g3;
92+
93+
clear_checks();
94+
fooBase(&b0);
95+
assert(a.checked > 0);
96+
97+
clear_checks();
98+
fooBase(&c0);
99+
assert(a.checked > 0);
100+
101+
clear_checks();
102+
fooBase(&c1);
103+
assert(a.checked == 0);
104+
assert(b.checked > 0);
105+
106+
clear_checks();
107+
fooBase(&g0);
108+
assert(a.checked > 0);
109+
assert(b.checked == 0);
110+
assert(c.checked == 0);
111+
112+
clear_checks();
113+
fooBase(&g1);
114+
assert(a.checked == 0);
115+
assert(b.checked == 0);
116+
assert(c.checked > 0);
117+
118+
119+
clear_checks();
120+
fooBase(&g2);
121+
assert(a.checked > 0);
122+
assert(b.checked > 0);
123+
assert(c.checked == 0);
124+
125+
126+
clear_checks();
127+
fooBase(&g3);
128+
assert(a.checked == 0);
129+
assert(b.checked > 0);
130+
assert(c.checked > 0);
131+
132+
clear_checks();
133+
b0.f();
134+
assert(a.checked > 0);
135+
136+
clear_checks();
137+
c0.f();
138+
assert(a.checked > 0);
139+
140+
clear_checks();
141+
c1.f();
142+
assert(a.checked == 0);
143+
assert(b.checked > 0);
144+
145+
clear_checks();
146+
g0.f();;
147+
assert(a.checked > 0);
148+
assert(b.checked == 0);
149+
assert(c.checked == 0);
150+
151+
152+
clear_checks();
153+
g1.f();
154+
assert(a.checked == 0);
155+
assert(b.checked == 0);
156+
assert(c.checked > 0);
157+
158+
159+
clear_checks();
160+
g2.f();
161+
assert(a.checked > 0);
162+
assert(b.checked > 0);
163+
assert(c.checked == 0);
164+
165+
clear_checks();
166+
g3.f();
167+
assert(a.checked == 0);
168+
assert(b.checked > 0);
169+
assert(c.checked > 0);
170+
171+
172+
return 0;
173+
}

0 commit comments

Comments
 (0)