| 1 |
// generic assert contract parsing checks |
| 2 |
// ensure that existing generalized attribute parsing is not intefered with |
| 3 |
// ensure that an assert contract cannot chain into an empty attribute list |
| 4 |
// ensure that an attribute list cannot chain into an assert contract |
| 5 |
// { dg-do compile } |
| 6 |
// { dg-options "-std=c++2a -fcontracts" } |
| 7 |
|
| 8 |
constexpr bool fun(int x) { |
| 9 |
return x < 0; |
| 10 |
} |
| 11 |
|
| 12 |
namespace tns { |
| 13 |
constexpr bool f(int x) { |
| 14 |
return x < 0; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
bool assert(int x) { |
| 19 |
return x < 0; |
| 20 |
} |
| 21 |
|
| 22 |
int main() |
| 23 |
{ |
| 24 |
constexpr int x = 1; |
| 25 |
[[fun(x)]]; // { dg-warning "attributes at the beginning of statement are ignored" } |
| 26 |
[[fun(x), assert(x)]]; // { dg-warning "attributes at the beginning of statement are ignored" } |
| 27 |
|
| 28 |
[[assert default: fun(x), ]]; // { dg-error "expected ']'" } |
| 29 |
[[assert default: fun(x) ]]; |
| 30 |
|
| 31 |
[[fun(x), assert default: fun(x)]]; // { dg-error "expected .]. before .default." } |
| 32 |
// { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 } |
| 33 |
[[fun(x), assert: fun(x)]]; // { dg-error "expected .]. before .:. token" } |
| 34 |
// { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 } |
| 35 |
[[fun(x), assert fun(x)]]; // { dg-error "expected .]. before .fun." } |
| 36 |
// { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 } |
| 37 |
[[ using tns: f(x) ]]; // { dg-warning "attributes at the beginning of statement are ignored" } |
| 38 |
[[ using tns: f(x), assert default: fun(x) ]]; // { dg-error "expected .]. before .default." } |
| 39 |
// { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 } |
| 40 |
[[ using tns: f(x), , default: fun(x) ]]; // { dg-error "expected .]. before .:." } |
| 41 |
// { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 } |
| 42 |
return 0; |
| 43 |
} |