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