forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from NinaRanns/contracts-constify
constification of postcondition variable, automatic variables, and pa…
- Loading branch information
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// generic assert contract parsing checks | ||
// check omitted, 'default', 'audit', and 'axiom' contract levels parse | ||
// check that all concrete semantics parse | ||
// check omitted, '%default' contract roles parse | ||
// ensure that an invalid contract level 'invalid' errors | ||
// ensure that a predicate referencing an undefined variable errors | ||
// ensure that a missing colon after contract level errors | ||
// ensure that an invalid contract role 'invalid' errors | ||
// ensure that a missing colon after contract role errors | ||
// { dg-do compile } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr " } | ||
|
||
static_assert (__cpp_contracts >= 201906); | ||
static_assert (__cpp_contracts_literal_semantics >= 201906); | ||
static_assert (__cpp_contracts_roles >= 201906); | ||
|
||
int gi = 7; | ||
|
||
void f1(int i) pre(i++); // { dg-error "increment of read-only location" } | ||
void f2(int &i) pre(i++); // { dg-error "increment of read-only location" } | ||
void f3(int *i) pre(i++); // { dg-error "increment of read-only location" } | ||
void f4(int *i) pre((*i)++); // ok, not deep const | ||
void f5(int *i) pre(gi++); // ok, non automatic storage | ||
|
||
// todo structured binding test | ||
// lambda tests | ||
// template tests | ||
int main() | ||
{ | ||
int i; | ||
contract_assert(i++); // { dg-error "increment of read-only location" } | ||
i = 5; | ||
|
||
int& ri = i; | ||
contract_assert(ri++); // { dg-error "increment of read-only location" } | ||
ri = 6; | ||
|
||
int *pi= &i; | ||
contract_assert(pi++); // { dg-error "increment of read-only location" } | ||
contract_assert((*pi)++); // ok, not deep const | ||
|
||
contract_assert(i == 4 ? i : i ); // ok, no name clash | ||
|
||
|
||
return 0; | ||
} |