2 // { dg-do run { target c++23 } }
4 // lambda capture mutability with explicit object parameter
6 void capture_by_value()
8 static constexpr int magic = 42;
9 auto f0 = [n = 0](this auto self){
13 auto f1 = [n = 0](this auto& self){
17 auto f2 = [n = 0](this auto&& self){
22 // passed by value, should still return a value equal to magic regardless
23 // of how many times it is called
28 // passed by reference, the returned value should increase by magic
29 // each time it is called
32 if (f1 () != magic + magic)
36 if (f2 () != magic + magic)
42 static constexpr int magic = 42;
44 auto f0 = [&n0](this auto self){
48 auto f1 = [&n1](this auto& self){
52 auto f2 = [&n2](this auto&& self){
56 auto f3 = [&n3](this auto const& self){
60 // all calls should mutate their capture, the capture is by reference
61 if (f0 (); n0 != magic)
63 if (f0 (); n0 != magic + magic)
66 if (f1 (); n1 != magic)
68 if (f1 (); n1 != magic + magic)
71 if (f2 (); n2 != magic)
73 if (f2 (); n2 != magic + magic)
76 if (f3 (); n3 != magic)
78 if (f3 (); n3 != magic + magic)