| 1 |
// generic pre contract parsing checks |
| 2 |
// check omitted, 'default', 'audit', and 'axiom' contract levels parse |
| 3 |
// ensure that an invalid contrcat level 'off' errors |
| 4 |
// ensure that a predicate referencing an undefined variable errors |
| 5 |
// ensure that a missing colon after contract level errors |
| 6 |
// { dg-do compile } |
| 7 |
// { dg-options "-std=c++2a -fcontracts" } |
| 8 |
|
| 9 |
void f1(int x) [[ pre: x >= 0 ]] { } |
| 10 |
void f2(int x) [[ pre default: x >= 0 ]] { } |
| 11 |
void f3(int x) [[ pre audit: x >= 0 ]] { } |
| 12 |
void f4(int x) [[ pre axiom: x >= 0 ]] { } |
| 13 |
|
| 14 |
void finvalid(int x) [[ pre invalid: x >= 0 ]] { } // { dg-error "expected contract level" } |
| 15 |
void fundeclared() [[ pre: x >= 0 ]] { } // { dg-error ".x. was not declared in this scope" } |
| 16 |
void fmissingcolon(int x) [[ pre default x == 0]] { } // { dg-error "expected .:. before .x." } |
| 17 |
|
| 18 |
int Z; |
| 19 |
void (*fp1)(int x) [[ pre: Z > 0 ]]; // { dg-error "contracts must appertain" } |
| 20 |
void (*fp2 [[ pre: Z > 0 ]])(int x); // { dg-error "contracts must appertain" } |
| 21 |
typedef void (*fp3)(int x) [[ pre: Z > 0 ]]; // { dg-error "contracts must appertain" } |
| 22 |
typedef void (*fp4 [[ pre: Z > 0 ]])(int x); // { dg-error "contracts must appertain" } |
| 23 |
fp3 fn5(int a) [[ pre: a > 0 ]]; // { dg-bogus "contracts must appertain" } |
| 24 |
|
| 25 |
int xyz; |
| 26 |
[[ pre: xyz ]] struct Bar; // { dg-error "contracts must appertain" } |
| 27 |
// { dg-warning "attribute ignored" "" { target *-*-* } .-1 } |
| 28 |
struct [[ pre: xyz ]] Bar; // { dg-error "contracts must appertain" } |
| 29 |
struct Bar [[ pre: xyz ]]; // { dg-error "contracts must appertain" } |
| 30 |
struct Zoo {} x [[ pre: xyz ]]; // { dg-error "contracts must appertain" } |
| 31 |
|
| 32 |
void f6(int x) [[ pre: x > 0 ; // { dg-error "expected .]." } |
| 33 |
void f7(int x) [[ pre: x > 0 ]; // { dg-error "expected .]." } |
| 34 |
void f8(int x) [[ pre: x > 0 { }; // { dg-error "expected .]." } |
| 35 |
void f9(int x) [[ pre: x > 0 ] { }; // { dg-error "expected .]." } |
| 36 |
|