| 1 |
// P0847R7 |
| 2 |
// { dg-do compile { target c++23 } } |
| 3 |
|
| 4 |
// diagnose mutation of lambda capture when called with a deduced as const explicit object parameter |
| 5 |
|
| 6 |
void test() |
| 7 |
{ |
| 8 |
auto f0 = [n = 5](this auto){ n = 10; }; // { dg-bogus {assignment of read-only variable} } |
| 9 |
auto f1 = [n = 5](this auto const){ n = 10; }; // { dg-error {assignment of read-only variable} } |
| 10 |
auto f2 = [n = 5](this auto&){ n = 10; }; // { dg-error {assignment of read-only variable} } |
| 11 |
auto f3 = [n = 5](this auto const&){ n = 10; }; // { dg-error {assignment of read-only variable} } |
| 12 |
auto f4 = [n = 5](this auto&&){ n = 10; }; // { dg-error {assignment of read-only variable} } |
| 13 |
|
| 14 |
static_cast<decltype(f0) const&>(f0)(); |
| 15 |
f1(); |
| 16 |
static_cast<decltype(f2) const&>(f2)(); |
| 17 |
f3(); |
| 18 |
static_cast<decltype(f4) const&>(f4)(); |
| 19 |
} |
| 20 |
|