| 1 |
// generic assert contract parsing checks |
| 2 |
// check omitted, 'default', 'audit', and 'axiom' contract levels parse |
| 3 |
// check that all concrete semantics parse |
| 4 |
// check omitted, '%default' contract roles parse |
| 5 |
// ensure that an invalid contract level 'invalid' errors |
| 6 |
// ensure that a predicate referencing an undefined variable errors |
| 7 |
// ensure that a missing colon after contract level errors |
| 8 |
// ensure that an invalid contract role 'invalid' errors |
| 9 |
// ensure that a missing colon after contract role errors |
| 10 |
// { dg-do compile } |
| 11 |
// { dg-options "-std=c++2a -fcontracts" } |
| 12 |
|
| 13 |
static_assert (__cpp_contracts >= 201906); |
| 14 |
static_assert (__cpp_contracts_literal_semantics >= 201906); |
| 15 |
static_assert (__cpp_contracts_roles >= 201906); |
| 16 |
|
| 17 |
int main() |
| 18 |
{ |
| 19 |
int x; |
| 20 |
|
| 21 |
[[assert: x >= 0]]; |
| 22 |
[[assert default: x < 0]]; |
| 23 |
[[assert audit: x == 0]]; |
| 24 |
[[assert axiom: x == 1]]; |
| 25 |
|
| 26 |
[[assert: x > 0 ? true : false]]; |
| 27 |
[[assert: x < 0 ? true : false]]; |
| 28 |
|
| 29 |
[[assert: x = 0]]; // { dg-error "expected .]. before .=. token" } |
| 30 |
|
| 31 |
[[assert ignore: x >= 0]]; |
| 32 |
[[assert assume: x >= 0]]; |
| 33 |
[[assert check_never_continue: x >= 0]]; |
| 34 |
[[assert check_maybe_continue: x >= 0]]; |
| 35 |
|
| 36 |
[[assert %default: x >= 0]]; |
| 37 |
[[assert default %default: x < 0]]; |
| 38 |
[[assert audit %default: x == 0]]; |
| 39 |
[[assert axiom %default: x == 1]]; |
| 40 |
|
| 41 |
[[assert check_always_continue: x >= 0]]; // { dg-error "expected contract level" } |
| 42 |
[[assert invalid: x == 0]]; // { dg-error "expected contract level" } |
| 43 |
[[assert: y == 0]]; // { dg-error ".y. was not declared in this scope" } |
| 44 |
[[assert default x == 0]]; // { dg-error "expected .:. before .x." } |
| 45 |
[[assert %default x >= 0]]; // { dg-error "expected .:. before .x." } |
| 46 |
|
| 47 |
[[assert %invalid: x >= 0]]; // TODO: optional warning? |
| 48 |
return 0; |
| 49 |
} |