| 1 |
// Tests to ensure that contracts have a properly cv qualified this |
| 2 |
// { dg-do compile } |
| 3 |
// { dg-options "-std=c++2a -fcontracts" } |
| 4 |
|
| 5 |
struct S |
| 6 |
{ |
| 7 |
int g() const { return x_; } |
| 8 |
int f() { return x_; } |
| 9 |
|
| 10 |
void mem_c() const |
| 11 |
[[ pre: f() ]] // { dg-error "discards qualifiers" } |
| 12 |
{ |
| 13 |
} |
| 14 |
void mem_nc() |
| 15 |
[[ pre: f() ]] |
| 16 |
{ |
| 17 |
} |
| 18 |
|
| 19 |
void memc_c() const |
| 20 |
[[ pre: g() ]] |
| 21 |
{ |
| 22 |
} |
| 23 |
void memc_nc() |
| 24 |
[[ pre: g() ]] |
| 25 |
{ |
| 26 |
} |
| 27 |
|
| 28 |
private: |
| 29 |
int x_{-10}; |
| 30 |
}; |
| 31 |
|
| 32 |
int main(int, char**) |
| 33 |
{ |
| 34 |
S s; |
| 35 |
return 0; |
| 36 |
}; |
| 37 |
|