Skip to content

Commit

Permalink
Merge pull request #4 from NinaRanns/contracts-nonattr
Browse files Browse the repository at this point in the history
fixing tests and removing C++20 requirement
  • Loading branch information
NinaRanns authored May 29, 2024
2 parents 9ec18b3 + 8082707 commit 4c447ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gcc/c-family/c-common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ const struct c_common_resword c_common_reswords[] =
{ "constinit", RID_CONSTINIT, D_CXXONLY | D_CXX20 | D_CXXWARN },
{ "const_cast", RID_CONSTCAST, D_CXXONLY | D_CXXWARN },
{ "continue", RID_CONTINUE, 0 },
{ "contract_assert", RID_CONTASSERT, D_CXXONLY | D_CXX20 | D_CXXWARN },
{ "contract_assert", RID_CONTASSERT, D_CXXONLY | D_CXXWARN }, // removed D_CXX20 in order for contracts to work out of the box
{ "decltype", RID_DECLTYPE, D_CXXONLY | D_CXX11 | D_CXXWARN },
{ "default", RID_DEFAULT, 0 },
{ "delete", RID_DELETE, D_CXXONLY | D_CXXWARN },
Expand Down
18 changes: 10 additions & 8 deletions gcc/testsuite/g++.dg/contracts/new/contract-assert_err.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ static_assert (__cpp_contracts_literal_semantics >= 201906);
static_assert (__cpp_contracts_roles >= 201906);


contract_assert f(); // { dg-error "expected unqualified-id before" }
void f(contract_assert); // { dg-error "expected primary-expression before"}
struct contract_assert{}; // { dg-error "expected unqualified-id before" }
void contract_assert();
contract_assert f(); // { dg-error "expected unqualified-id before .contract_assert." }

void f(contract_assert); // { dg-error "expected primary-expression before|declared void" }
struct contract_assert{}; // { dg-error "expected unqualified-id before|expected identifier" }
void contract_assert(); // { dg-error "expected unqualified-id before" }

int main()
{

contract_assert(x==0); // { dg-error }
contract_assert int i = 0; // { dg-error }
contract_assert(x==0); // { dg-error ".x. was not declared in this scope"}
contract_assert int i = 0; // // { dg-error "expected primary-expression before|before .int." }

i = 7;
[[assert: i == 0]] contract_assert(x==0); // { dg-error }
[[assert: i == 0]] contract_assert(x==0); // { dg-error "assertions must be followed by" }

contract_assert( x = 0); // { dg-error "expected .). before .=. token"}
contract_assert( x = 0); // { dg-error "expected primary-expression before|expected .\\). before .=. token" }

contract_assert( y == 0); // { dg-error ".y. was not declared in this scope" }
return 0;
Expand Down
14 changes: 10 additions & 4 deletions gcc/testsuite/g++.dg/contracts/new/init-declarator.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
static_assert (__cpp_contracts >= 201906);
static_assert (__cpp_contracts_literal_semantics >= 201906);
static_assert (__cpp_contracts_roles >= 201906);
i

// { dg-prune-output "warning" }
// { dg-prune-output "note" }

int fun(int n) pre (n > 0 );

int main()
{
int x() [[ pre fun(0) > 0 ]];
int y() pre (fun(0) > 0);
int z() [[ pre fun(0) > 0 ]] pre (fun(0) > 0);
int x() [[ pre fun(0) > 0 ]]; /* { dg-error "expected contract level" "" { target *-*-* } } */
/* { dg-error "before .\\(." "" { target *-*-* } .-1 } */
int y() pre (fun(0) > 0); // { dg-error "was not declared"}
int z() [[ pre fun(0) > 0 ]] pre (fun(0) > 0); /* { dg-error "expected contract" "" { target *-*-* } } */
/* { dg-error "before .\\(." "" { target *-*-* } .-1 } */

return 0;
}

0 comments on commit 4c447ed

Please sign in to comment.