Skip to content

Commit 2fec629

Browse files
Merge pull request gcc-mirror#94 from NinaRanns/non_odr_parm_in_post
fixing parameter constness check in postconditions
2 parents 1b837a3 + 7c6222b commit 2fec629

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

gcc/cp/contracts.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2791,8 +2791,8 @@ maybe_reject_param_in_postcondition (tree decl, location_t location)
27912791
{
27922792
if (flag_contracts_nonattr
27932793
&& TREE_CODE (decl) == PARM_DECL
2794-
&& should_constify_contract
27952794
&& processing_postcondition
2795+
&& !cp_unevaluated_operand
27962796
&& !(REFERENCE_REF_P (decl)
27972797
&& TREE_CODE (TREE_OPERAND (decl, 0)) == PARM_DECL)
27982798
/* Return value parameter has DECL_ARTIFICIAL flag set. The flag

gcc/testsuite/g++.dg/contracts/cpp26/constification_mutable.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void f6(int i) pre mutable(i++);
2828
void f7(int &i) pre mutable(i++);
2929
void f8(int *i) pre mutable(i++);
3030
void f9(int *i) pre mutable(gi++);
31-
31+
void f10(int i) post mutable(i > 5); // { dg-error "used in a postcondition must be const" }
3232
// todo structured binding test
3333
// lambda tests
3434
// template tests

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,67 @@ namespace nonFirstDeclarationNegative
243243
void PostCondT<T>::f (U i){}
244244

245245
}
246+
247+
namespace checkNonOdr{
248+
249+
int f (int i, int *j)
250+
post ( sizeof(i) )
251+
post ( noexcept(check (&j)));
252+
253+
254+
template <class T>
255+
int f (T i, T *j)
256+
post ( sizeof(i) )
257+
post ( noexcept(check (&j)));
258+
259+
struct PostCond {
260+
261+
PostCond (int i, int *j)
262+
post ( sizeof(i) )
263+
post ( noexcept(check (&j)));
264+
265+
266+
template <class T>
267+
PostCond (T i, T *j)
268+
post ( sizeof(i) )
269+
post ( noexcept(check (&j)));
270+
271+
int f (int i, int *j)
272+
post ( sizeof(i) )
273+
post ( noexcept(check (&j)));
274+
275+
template <class T>
276+
int f (T i, T *j)
277+
post ( sizeof(i) )
278+
post ( noexcept(check (&j)));
279+
};
280+
281+
template <typename T>
282+
struct PostCondT
283+
{
284+
285+
PostCondT (int i, int *j)
286+
post ( sizeof(i) )
287+
post ( noexcept(check (&j)));
288+
289+
template <class U>
290+
PostCondT (U i, U *j)
291+
post ( sizeof(i) )
292+
post ( noexcept(check (&j)));
293+
294+
int f (int i, int *j)
295+
post ( sizeof(i) )
296+
post ( noexcept(check (&j)));
297+
298+
int f (T i, T *j)
299+
post ( sizeof(i) )
300+
post ( noexcept(check (&j)));
301+
302+
template <class U>
303+
int f (U i, U *j)
304+
post ( sizeof(i) )
305+
post ( noexcept(check (&j)));
306+
};
307+
308+
309+
}

0 commit comments

Comments
 (0)