Skip to content

Commit 8b9af00

Browse files
committed
adding negative tests
1 parent 742d56f commit 8b9af00

File tree

4 files changed

+117
-14
lines changed

4 files changed

+117
-14
lines changed

gcc/testsuite/g++.dg/contracts/cpp26/P2900R13-virtual-func/postcondition-const-check-redecl.C

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,23 @@ struct Base
2020
struct Derived : Base
2121
{
2222
virtual void f (const NTClass i) post (check (i));
23+
virtual void g (const NTClass i) pre ( check (i)) post (true);
2324
};
2425

2526
struct DerivedV : virtual Base
2627
{
2728
virtual void f (const NTClass i) post (check (i));
29+
virtual void g (const NTClass i) pre ( check (i)) post (true);
2830
};
2931

3032
void
3133
Derived::f (NTClass i){} // { dg-error "used in a postcondition must be const" }
3234

3335
void
3436
DerivedV::f (NTClass i){} // { dg-error "used in a postcondition must be const" }
37+
38+
void
39+
Derived::g (NTClass i){}
40+
41+
void
42+
DerivedV::g (NTClass i){}

gcc/testsuite/g++.dg/contracts/cpp26/P3653-virtual-func/postcondition-const-check-redecl.C

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,23 @@ struct Base
2020
struct Derived : Base
2121
{
2222
virtual void f (const NTClass i) post (check (i));
23+
virtual void g (const NTClass i) pre ( check (i)) post (true);
2324
};
2425

2526
struct DerivedV : virtual Base
2627
{
2728
virtual void f (const NTClass i) post (check (i));
29+
virtual void g (const NTClass i) pre ( check (i)) post (true);
2830
};
2931

3032
void
3133
Derived::f (NTClass i){} // { dg-error "used in a postcondition must be const" }
3234

3335
void
3436
DerivedV::f (NTClass i){} // { dg-error "used in a postcondition must be const" }
37+
38+
void
39+
Derived::g (NTClass i){}
40+
41+
void
42+
DerivedV::g (NTClass i){}

gcc/testsuite/g++.dg/contracts/cpp26/P3653-virtual-func/postcondition-const-check.C

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ struct Base
1515
{
1616
virtual void f (const NTClass i) post (check (i));
1717
virtual void f (const int i) post (check (i));
18-
19-
18+
virtual void g (const NTClass i, int& j) pre ( check (i)) post (check(j));
2019
} ;
2120

2221
struct Derived : Base
2322
{
2423
void f (NTClass i); // { dg-error "used in a postcondition must be const" }
24+
25+
void g (NTClass i, int& j);
2526
};
2627

2728
struct DerivedV : virtual Base
2829
{
2930
void f (NTClass i); // { dg-error "used in a postcondition must be const" }
31+
32+
void g (NTClass i, int& j);
3033
};
3134

3235
template<typename T>
@@ -35,6 +38,8 @@ struct DerivedT : Base
3538
void f (NTClass i) {};
3639

3740
void f (T i) {};
41+
42+
void g (NTClass i, T& j);
3843
};
3944

4045
template<typename T>
@@ -43,6 +48,8 @@ template<typename T>
4348
void f (NTClass i) {};
4449

4550
void f (T i) {};
51+
52+
void g (NTClass i, T& j);
4653
};
4754

4855
template<typename T>
@@ -51,6 +58,8 @@ struct BaseT
5158
virtual void f (const NTClass i) post (check (i));
5259

5360
virtual void f (const T i) post (check (i));
61+
62+
virtual void g (const NTClass i, T& j) pre ( check (i)) post (check(j));
5463
};
5564

5665
template<typename T>
@@ -59,6 +68,8 @@ struct DerivedTT : BaseT<T>
5968
void f (NTClass i) {};
6069

6170
void f (T i) {};
71+
72+
void g (NTClass i, T& j);
6273
};
6374

6475
template <typename T>
@@ -67,6 +78,8 @@ struct DerivedTVT : virtual BaseT<T>
6778
void f (NTClass i) {};
6879

6980
void f (T i) {};
81+
82+
void g (NTClass i, T& j);
7083
};
7184

7285
// adding DerivedT2 for diagnostic disambiguation purposes
@@ -76,6 +89,8 @@ struct DerivedT2 : Base
7689
void f (NTClass i) {};
7790

7891
void f (T i) {};
92+
93+
void g (NTClass i, T& j);
7994
};
8095

8196
// adding DerivedTV2 for diagnostic disambiguation purposes
@@ -85,6 +100,8 @@ struct DerivedTV2 : virtual Base
85100
void f (NTClass i) {};
86101

87102
void f (T i) {};
103+
104+
void g (NTClass i, T& j);
88105
};
89106

90107
template<typename T>
@@ -93,6 +110,8 @@ struct DerivedTT2 : BaseT<T>
93110
void f (NTClass i) {};
94111

95112
void f (int i) {};
113+
114+
void g (NTClass i, T& j);
96115
};
97116

98117
template <typename T>
@@ -101,39 +120,41 @@ struct DerivedTVT2 : virtual BaseT<T>
101120
void f (NTClass i) {};
102121

103122
void f (int i) {};
123+
124+
void g (NTClass i, T& j);
104125
};
105126

106127

107128
int main()
108129
{
109130
DerivedT<int> dt;
110-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 35 }
111-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 37 }
131+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 38 }
132+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 40 }
112133

113134
DerivedTV<int> dvt;
114-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 43 }
115-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 45 }
135+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 48 }
136+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 50 }
116137

117138

118139
DerivedTT<int> dt2;
119-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 59 }
120-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 61 }
140+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 68 }
141+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 70 }
121142

122143
DerivedTVT<int> dvt2;
123-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 67 }
124-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 69 }
144+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 78 }
145+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 80 }
125146

126147

127148
DerivedT2<char> dtc;
128-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 76 }
149+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 89 }
129150

130151
DerivedTV2<char> dvtc;
131-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 85 }
152+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 100 }
132153

133154
DerivedTT2<char> dtc2;
134-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 93 }
155+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 110 }
135156

136157
DerivedTVT2<char> dvtc2;
137-
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 101 }
158+
// { dg-error {used in a postcondition must be const} "" { target *-*-* } 120 }
138159

139160
}

gcc/testsuite/g++.dg/contracts/cpp26/postcondition-const-check.C

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,69 @@ namespace nonFirstDeclaration
177177
void PostCondT<T>::f (U i){} // { dg-error "used in a postcondition must be const" }
178178

179179
}
180+
181+
namespace nonFirstDeclarationNegative
182+
{
183+
184+
int f (const NTClass i)
185+
post ( check (true))
186+
pre ( check (i));
187+
188+
template <class T>
189+
int f (const T i)
190+
post ( check (true))
191+
pre ( check (i));
192+
193+
struct PostCond {
194+
void f (const NTClass i)
195+
post ( check (true))
196+
pre ( check (i));
197+
198+
template <class T>
199+
void f (const T i)
200+
post ( check (true))
201+
pre ( check (i));
202+
};
203+
204+
template <typename T>
205+
struct PostCondT
206+
{
207+
void f (const NTClass i)
208+
post ( check (true))
209+
pre ( check (i));
210+
211+
void f (const T i)
212+
post ( check (true))
213+
pre ( check (i));
214+
215+
template <class U>
216+
void f (const U i)
217+
post ( check (true))
218+
pre ( check (i));
219+
};
220+
221+
int
222+
f (NTClass i);
223+
224+
template<class T>
225+
int
226+
f (T i);
227+
228+
void
229+
PostCond::f (NTClass i){}
230+
231+
template<class T>
232+
void
233+
PostCond::f (T i){}
234+
235+
template<typename T>
236+
void PostCondT<T>::f (NTClass i){}
237+
238+
template<typename T>
239+
void PostCondT<T>::f (T i){}
240+
241+
template<typename T>
242+
template<typename U>
243+
void PostCondT<T>::f (U i){}
244+
245+
}

0 commit comments

Comments
 (0)