1 // RUN: %clang_cc1 -emit-pch -std=c++23 -o %t %s
2 // RUN: %clang_cc1 -include-pch %t -verify -fsyntax-only -DTEST -std=c++23 %s
3
4 // Test that dependence of 'this' and DREs due to by-value capture by a
5 // lambda with an explicit object parameter is serialised/deserialised
6 // properly.
7
8 #ifndef HEADER
9 #define HEADER
10 struct S {
11 int x;
fS12 auto f() {
13 return [*this] (this auto&&) {
14 int y;
15 x = 42;
16
17 const auto l = [y] (this auto&&) { y = 42; };
18 l();
19 };
20 }
21 };
22 #endif
23
24 // expected-error@* {{read-only variable is not assignable}}
25 // expected-error@* {{cannot assign to a variable captured by copy in a non-mutable lambda}}
26 // expected-note@* 2 {{in instantiation of}}
27
28 #ifdef TEST
f()29 void f() {
30 const auto l = S{}.f();
31 l(); // expected-note {{in instantiation of}}
32 }
33 #endif
34
35
36