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 #3 from NinaRanns/contracts-nonattr
contract_assert
- Loading branch information
Showing
11 changed files
with
242 additions
and
5 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
26 changes: 26 additions & 0 deletions
26
gcc/testsuite/g++.dg/contracts/new/contract-assert-disabled.C
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,26 @@ | ||
// 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 " } | ||
|
||
static_assert (__cpp_contracts >= 201906); | ||
static_assert (__cpp_contracts_literal_semantics >= 201906); | ||
static_assert (__cpp_contracts_roles >= 201906); | ||
|
||
// { dg-prune-output "expected primary-expression" } | ||
|
||
int main() | ||
{ | ||
int x; | ||
|
||
contract_assert( x >= 0); // { dg-error "'contract_assertions' are only available with" } | ||
|
||
return 0; | ||
} |
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,59 @@ | ||
// 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 run } | ||
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-continuation-mode=on" } | ||
#include <iostream> | ||
#include <experimental/contract> | ||
|
||
#define VERIFY_ASSERT(statement, asserts) \ | ||
{ \ | ||
bool violation = false;\ | ||
try{ \ | ||
statement; \ | ||
} catch(int &ex) { \ | ||
violation = true; \ | ||
} \ | ||
if ((asserts && !violation) || (!(asserts) && violation)) __builtin_abort(); \ | ||
} \ | ||
|
||
static_assert (__cpp_contracts >= 201906); | ||
static_assert (__cpp_contracts_literal_semantics >= 201906); | ||
static_assert (__cpp_contracts_roles >= 201906); | ||
|
||
void handle_contract_violation(const std::experimental::contract_violation &violation) { | ||
std::cerr << "custom std::handle_contract_violation called:" | ||
<< " " << violation.line_number() | ||
<< " " << violation.file_name() | ||
<< std::endl; | ||
throw -(int)violation.line_number(); | ||
} | ||
|
||
void foo(int x) pre (x>10){}; | ||
|
||
int main() | ||
{ | ||
VERIFY_ASSERT([[assert: false]], true); | ||
VERIFY_ASSERT([[assert: true]], false); | ||
|
||
VERIFY_ASSERT(contract_assert(true), false); | ||
VERIFY_ASSERT(contract_assert(false), true); | ||
|
||
int i = 4; | ||
VERIFY_ASSERT(foo(i), true); | ||
VERIFY_ASSERT(contract_assert( i == 4 ? true : false), false) | ||
VERIFY_ASSERT(contract_assert( i > 4 ? true : false), true) | ||
|
||
i = 18; | ||
VERIFY_ASSERT(foo(i), false); | ||
VERIFY_ASSERT(contract_assert( i == 4 ? true : false), true) | ||
VERIFY_ASSERT(contract_assert( i > 4 ? true : false), false) | ||
|
||
return 0; | ||
} |
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,41 @@ | ||
// 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 main() | ||
{ | ||
int x; | ||
|
||
contract_assert( x >= 0); | ||
contract_assert( x < 0); | ||
contract_assert( x == 0); | ||
|
||
contract_assert( x > 0 ? true : false); | ||
contract_assert( x < 0 ? true : false); | ||
|
||
contract_assert( x >= 0); | ||
contract_assert( x >= 0); | ||
contract_assert( x >= 0); | ||
contract_assert( x >= 0); | ||
|
||
contract_assert( x >= 0); | ||
contract_assert( x < 0); | ||
contract_assert( x == 0); | ||
contract_assert( x == 1); | ||
|
||
|
||
|
||
return 0; | ||
} |
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,37 @@ | ||
// 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" } | ||
|
||
// { dg-prune-output "not declared" } | ||
|
||
static_assert (__cpp_contracts >= 201906); | ||
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(); | ||
int main() | ||
{ | ||
|
||
contract_assert(x==0); // { dg-error } | ||
contract_assert int i = 0; // { dg-error } | ||
|
||
i = 7; | ||
[[assert: i == 0]] contract_assert(x==0); // { dg-error } | ||
|
||
contract_assert( x = 0); // { dg-error "expected .). before .=. token"} | ||
|
||
contract_assert( y == 0); // { dg-error ".y. was not declared in this scope" } | ||
return 0; | ||
} |
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,25 @@ | ||
// 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); | ||
i | ||
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); | ||
return 0; | ||
} |
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