xref: /llvm-project/clang/test/SemaCXX/lambda-expressions.cpp (revision 7339c0f782d5c70e0928f8991b0c05338a90c84c)
1 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify -verify=expected-cxx14 -fblocks %s
2 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s | FileCheck %s
3 
4 namespace std { class type_info; };
5 
6 namespace ExplicitCapture {
7   class C {
8     int Member;
9 
10     static void Overload(int);
11     void Overload();
12     virtual C& Overload(float);
13 
14     void ImplicitThisCapture() {
15       []() { (void)Member; };     // expected-error {{'this' cannot be implicitly captured in this context}} expected-note {{explicitly capture 'this'}}
16       const int var = []() {(void)Member; return 0; }(); // expected-error {{'this' cannot be implicitly captured in this context}} expected-note {{explicitly capture 'this'}}
17       [&](){(void)Member;};
18 
19       [this](){(void)Member;};
20       [this]{[this]{};};
21       []{[this]{};};// expected-error {{'this' cannot be implicitly captured in this context}}
22       []{Overload(3);};
23       [] { Overload(); }; // expected-error {{'this' cannot be implicitly captured in this context}} expected-note {{explicitly capture 'this'}}
24       []{(void)typeid(Overload());};
25       [] { (void)typeid(Overload(.5f)); }; // expected-error {{'this' cannot be implicitly captured in this context}} expected-note {{explicitly capture 'this'}}
26     }
27   };
28 
29   void f() {
30     [this] () {}; // expected-error {{'this' cannot be captured in this context}}
31   }
32 }
33 
34 namespace ReturnDeduction {
35   void test() {
36     [](){ return 1; };
37     [](){ return 1; };
38     [](){ return ({return 1; 1;}); };
39     [](){ return ({return 'c'; 1;}); }; // expected-error {{must match previous return type}}
40     []()->int{ return 'c'; return 1; };
41     [](){ return 'c'; return 1; };  // expected-error {{must match previous return type}}
42     []() { return; return (void)0; };
43     [](){ return 1; return 1; };
44   }
45 }
46 
47 namespace ImplicitCapture {
48   void test() {
49     int a = 0; // expected-note 5 {{declared}}
50     []() { return a; }; // expected-error {{variable 'a' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{begins here}} expected-note 2 {{capture 'a' by}} expected-note 2 {{default capture by}}
51     [&]() { return a; };
52     [=]() { return a; };
53     [=]() { int* b = &a; }; // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const int *'}}
54     [=]() { return [&]() { return a; }; };
55     []() { return [&]() { return a; }; }; // expected-error {{variable 'a' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} expected-note 2 {{capture 'a' by}} expected-note 2 {{default capture by}}
56     []() { return ^{ return a; }; };// expected-error {{variable 'a' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} expected-note 2 {{capture 'a' by}} expected-note 2 {{default capture by}}
57     []() { return [&a] { return a; }; }; // expected-error 2 {{variable 'a' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note 2 {{lambda expression begins here}}  expected-note 4 {{capture 'a' by}} expected-note 4 {{default capture by}}
58     [=]() { return [&a] { return a; }; }; //
59 
60     const int b = 2;
61     []() { return b; };
62 
63     union { // expected-note {{declared}}
64       int c;
65       float d;
66     };
67     d = 3;
68     [=]() { return c; }; // expected-error {{unnamed variable cannot be implicitly captured in a lambda expression}}
69 
70     __block int e; // expected-note 2{{declared}}
71     [&]() { return e; }; // expected-error {{__block variable 'e' cannot be captured in a lambda expression}}
72     [&e]() { return e; }; // expected-error {{__block variable 'e' cannot be captured in a lambda expression}}
73 
74     int f[10]; // expected-note {{declared}}
75     [&]() { return f[2]; };
76     (void) ^{ return []() { return f[2]; }; }; // expected-error {{variable 'f' cannot be implicitly captured in a lambda with no capture-default specified}} \
77     // expected-note{{lambda expression begins here}} expected-note 2 {{capture 'f' by}} expected-note 2 {{default capture by}}
78 
79     struct G { G(); G(G&); int a; }; // expected-note 6 {{not viable}}
80     G g;
81     [=]() { const G* gg = &g; return gg->a; };
82     [=]() { return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error {{no matching constructor for initialization of 'G'}}
83     (void)^{ return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error 2 {{no matching constructor for initialization of 'const G'}}
84 
85     const int h = a; // expected-note {{declared}}
86     []() { return h; }; // expected-error {{variable 'h' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} expected-note 2 {{capture 'h' by}} expected-note 2 {{default capture by}}
87 
88     // References can appear in constant expressions if they are initialized by
89     // reference constant expressions.
90     int i;
91     int &ref_i = i; // expected-note {{declared}}
92     [] { return ref_i; }; // expected-error {{variable 'ref_i' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} expected-note 2 {{capture 'ref_i' by}} expected-note 2 {{default capture by}}
93 
94     static int j;
95     int &ref_j = j;
96     [] { return ref_j; }; // ok
97   }
98 }
99 
100 namespace SpecialMembers {
101   void f() {
102     auto a = []{}; // expected-note 2{{here}} expected-note 2{{candidate}}
103     decltype(a) b; // expected-error {{no matching constructor}}
104     decltype(a) c = a;
105     decltype(a) d = static_cast<decltype(a)&&>(a);
106     a = a; // expected-error {{copy assignment operator is implicitly deleted}}
107     a = static_cast<decltype(a)&&>(a); // expected-error {{copy assignment operator is implicitly deleted}}
108   }
109   struct P {
110     P(const P&) = delete; //expected-note {{deleted here}} // expected-cxx14-note {{deleted here}}
111   };
112   struct Q {
113     ~Q() = delete; // expected-note {{deleted here}}
114   };
115   struct R {
116     R(const R&) = default;
117     R(R&&) = delete;
118     R &operator=(const R&) = delete;
119     R &operator=(R&&) = delete;
120   };
121   void g(P &p, Q &q, R &r) {
122     // FIXME: The note attached to the second error here is just amazingly bad.
123     auto pp = [p]{}; // expected-error {{deleted constructor}} expected-cxx14-error {{deleted copy constructor of '(lambda}}
124     // expected-cxx14-note-re@-1 {{copy constructor of '(lambda at {{.*}})' is implicitly deleted because field '' has a deleted copy constructor}}
125     auto qq = [q]{}; // expected-error {{deleted function}} expected-note {{because}}
126 
127     auto a = [r]{}; // expected-note 2{{here}}
128     decltype(a) b = a;
129     decltype(a) c = static_cast<decltype(a)&&>(a); // ok, copies R
130     a = a; // expected-error {{copy assignment operator is implicitly deleted}}
131     a = static_cast<decltype(a)&&>(a); // expected-error {{copy assignment operator is implicitly deleted}}
132   }
133 }
134 
135 namespace PR12031 {
136   struct X {
137     template<typename T>
138     X(const T&);
139     ~X();
140   };
141 
142   void f(int i, X x);
143   void g() {
144     const int v = 10;
145     f(v, [](){});
146   }
147 }
148 
149 namespace Array {
150   int &f(int *p);
151   char &f(...);
152   void g() {
153     int n = -1;   // expected-note {{declared here}}
154     [=] {
155       int arr[n]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \
156                      expected-note {{read of non-const variable 'n' is not allowed in a constant expression}}
157     } ();
158 
159     const int m = -1;
160     [] {
161       int arr[m]; // expected-error{{negative size}}
162     } ();
163 
164     [&] {
165       int arr[m]; // expected-error{{negative size}}
166     } ();
167 
168     [=] {
169       int arr[m]; // expected-error{{negative size}}
170     } ();
171 
172     [m] {
173       int arr[m]; // expected-error{{negative size}}
174     } ();
175   }
176 }
177 
178 void PR12248()
179 {
180   unsigned int result = 0;
181   auto l = [&]() { ++result; };
182 }
183 
184 namespace ModifyingCapture {
185   void test() {
186     int n = 0;
187     [=] {
188       n = 1; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
189     };
190   }
191 }
192 
193 namespace VariadicPackExpansion {
194   template<typename T, typename U> using Fst = T;
195   template<typename...Ts> bool g(Fst<bool, Ts> ...bools);
196   template<typename...Ts> bool f(Ts &&...ts) {
197     return g<Ts...>([&ts] {
198       if (!ts)
199         return false;
200       --ts;
201       return true;
202     } () ...);
203   }
204   void h() {
205     int a = 5, b = 2, c = 3;
206     while (f(a, b, c)) {
207     }
208   }
209 
210   struct sink {
211     template<typename...Ts> sink(Ts &&...) {}
212   };
213 
214   template<typename...Ts> void local_class() {
215     sink {
216       [] (Ts t) {
217         struct S : Ts {
218           void f(Ts t) {
219             Ts &that = *this;
220             that = t;
221           }
222           Ts g() { return *this; };
223         };
224         S s;
225         s.f(t);
226         return s;
227       } (Ts()).g() ...
228     };
229   };
230   struct X {}; struct Y {};
231   template void local_class<X, Y>();
232 
233   template<typename...Ts> void nested(Ts ...ts) {
234     f(
235       // Each expansion of this lambda implicitly captures all of 'ts', because
236       // the inner lambda also expands 'ts'.
237       [&] {
238         return ts + [&] { return f(ts...); } ();
239       } () ...
240     );
241   }
242   template void nested(int, int, int);
243 
244   template<typename...Ts> void nested2(Ts ...ts) { // expected-note 2{{here}}
245     // Capture all 'ts', use only one.
246     f([&ts...] { return ts; } ()...);
247     // Capture each 'ts', use it.
248     f([&ts] { return ts; } ()...);
249     // Capture all 'ts', use all of them.
250     f([&ts...] { return (int)f(ts...); } ());
251     // Capture each 'ts', use all of them. Ill-formed. In more detail:
252     //
253     // We instantiate two lambdas here; the first captures ts$0, the second
254     // captures ts$1. Both of them reference both ts parameters, so both are
255     // ill-formed because ts can't be implicitly captured.
256     //
257     // FIXME: This diagnostic does not explain what's happening. We should
258     // specify which 'ts' we're referring to in its diagnostic name. We should
259     // also say which slice of the pack expansion is being performed in the
260     // instantiation backtrace.
261     f([&ts] { return (int)f(ts...); } ()...); // \
262     // expected-error 2{{'ts' cannot be implicitly captured}} \
263     // expected-note 2{{lambda expression begins here}} \
264     // expected-note 4 {{capture 'ts' by}} \
265     // expected-note 2 {{while substituting into a lambda}}
266   }
267   template void nested2(int); // ok
268   template void nested2(int, int); // expected-note 2 {{in instantiation of}}
269 }
270 
271 namespace PR13860 {
272   void foo() {
273     auto x = PR13860UndeclaredIdentifier(); // expected-error {{use of undeclared identifier 'PR13860UndeclaredIdentifier'}}
274     auto y = [x]() { };
275     static_assert(sizeof(y), "");
276   }
277 }
278 
279 namespace PR13854 {
280   auto l = [](void){};
281 }
282 
283 namespace PR14518 {
284   auto f = [](void) { return __func__; }; // no-warning
285 }
286 
287 namespace PR16708 {
288   auto L = []() {
289     auto ret = 0;
290     return ret;
291     return 0;
292   };
293 }
294 
295 namespace TypeDeduction {
296   struct S {};
297   void f() {
298     const S s {};
299     S &&t = [&] { return s; } ();
300 #if __cplusplus > 201103L
301     S &&u = [&] () -> auto { return s; } ();
302 #endif
303   }
304 }
305 
306 
307 namespace lambdas_in_NSDMIs {
308   template<class T>
309   struct L {
310       T t{};
311       T t2 = ([](int a) { return [](int b) { return b; };})(t)(t);
312   };
313   L<int> l;
314 
315   namespace non_template {
316     struct L {
317       int t = 0;
318       int t2 = ([](int a) { return [](int b) { return b; };})(t)(t);
319     };
320     L l;
321   }
322 }
323 
324 // PR18477: don't try to capture 'this' from an NSDMI encountered while parsing
325 // a lambda.
326 namespace NSDMIs_in_lambdas {
327   template<typename T> struct S { int a = 0; int b = a; };
328   void f() { []() { S<int> s; }; }
329 
330   auto x = []{ struct S { int n, m = n; }; };
331   auto y = [&]{ struct S { int n, m = n; }; }; // expected-error {{non-local lambda expression cannot have a capture-default}}
332   void g() { auto z = [&]{ struct S { int n, m = n; }; }; }
333 }
334 
335 namespace CaptureIncomplete {
336   struct Incomplete; // expected-note 2{{forward decl}}
337   void g(const Incomplete &a);
338   void f(Incomplete &a) {
339     (void) [a] {}; // expected-error {{incomplete}}
340     (void) [&a] {};
341 
342     (void) [=] { g(a); }; // expected-error {{incomplete}}
343     (void) [&] { f(a); };
344   }
345 }
346 
347 namespace CaptureAbstract {
348   struct S {
349     virtual void f() = 0; // expected-note {{unimplemented}}
350     int n = 0;
351   };
352   struct T : S {
353     constexpr T() {}
354     void f();
355   };
356   void f() {
357     constexpr T t = T();
358     S &s = const_cast<T&>(t);
359     // FIXME: Once we properly compute odr-use per DR712, this should be
360     // accepted (and should not capture 's').
361     [=] { return s.n; }; // expected-error {{abstract}}
362   }
363 }
364 
365 namespace PR18128 {
366   auto l = [=]{}; // expected-error {{non-local lambda expression cannot have a capture-default}}
367 
368   struct S {
369     int n;
370     int (*f())[true ? 1 : ([=]{ return n; }(), 0)];
371     // expected-error@-1 {{non-local lambda expression cannot have a capture-default}}
372     // expected-error@-2 {{invalid use of non-static data member 'n'}}
373     // expected-cxx14-error@-3 {{a lambda expression may not appear inside of a constant expression}}
374     int g(int k = ([=]{ return n; }(), 0));
375     // expected-error@-1 {{non-local lambda expression cannot have a capture-default}}
376     // expected-error@-2 {{invalid use of non-static data member 'n'}}
377 
378     int a = [=]{ return n; }(); // ok
379     int b = [=]{ return [=]{ return n; }(); }(); // ok
380     int c = []{ int k = 0; return [=]{ return k; }(); }(); // ok
381     int d = [] { return [=] { return n; }(); }();          // expected-error {{'this' cannot be implicitly captured in this context}} expected-note {{explicitly capture 'this'}}
382   };
383 }
384 
385 namespace PR18473 {
386   template<typename T> void f() {
387     T t(0);
388     (void) [=]{ int n = t; }; // expected-error {{deleted}} expected-note {{while substituting into a lambda}}
389   }
390 
391   template void f<int>();
392   struct NoCopy {
393     NoCopy(int);
394     NoCopy(const NoCopy &) = delete; // expected-note {{deleted}}
395     operator int() const;
396   };
397   template void f<NoCopy>(); // expected-note {{instantiation}}
398 }
399 
400 void PR19249() {
401   auto x = [&x]{}; // expected-error {{cannot appear in its own init}}
402 }
403 
404 namespace PR20731 {
405 template <class L, int X = sizeof(L)>
406 void Job(L l);
407 
408 template <typename... Args>
409 void Logger(Args &&... args) {
410   auto len = Invalid_Function((args)...);
411   // expected-error@-1 {{use of undeclared identifier 'Invalid_Function'}}
412   Job([len]() {});
413 }
414 
415 void GetMethod() {
416   Logger();
417   // expected-note@-1 {{in instantiation of function template specialization 'PR20731::Logger<>' requested here}}
418 }
419 
420 template <typename T>
421 struct A {
422   T t;
423   // expected-error@-1 {{field has incomplete type 'void'}}
424 };
425 
426 template <typename F>
427 void g(F f) {
428   auto a = A<decltype(f())>{};
429   // expected-note@-1 {{in instantiation of template class 'PR20731::A<void>' requested here}}
430   auto xf = [a, f]() {};
431   int x = sizeof(xf);
432 };
433 void f() {
434   g([] {});
435   // expected-note-re@-1 {{in instantiation of function template specialization 'PR20731::g<(lambda at {{.*}}>' requested here}}
436 }
437 
438 template <class _Rp> struct function {
439   template <class _Fp>
440   function(_Fp) {
441     static_assert(sizeof(_Fp) > 0, "Type must be complete.");
442   }
443 };
444 
445 template <typename T> void p(T t) {
446   auto l = some_undefined_function(t);
447   // expected-error@-1 {{use of undeclared identifier 'some_undefined_function'}}
448   function<void()>(([l]() {}));
449 }
450 void q() { p(0); }
451 // expected-note@-1 {{in instantiation of function template specialization 'PR20731::p<int>' requested here}}
452 }
453 
454 namespace lambda_in_default_mem_init {
455   template<typename T> void f() {
456     struct S { int n = []{ return 0; }(); };
457   }
458   template void f<int>();
459 
460   template<typename T> void g() {
461     struct S { int n = [](int n){ return n; }(0); };
462   }
463   template void g<int>();
464 }
465 
466 namespace error_in_transform_prototype {
467   template<class T>
468   void f(T t) {
469     // expected-error@+2 {{type 'int' cannot be used prior to '::' because it has no members}}
470     // expected-error@+1 {{no member named 'ns' in 'error_in_transform_prototype::S'}}
471     auto x = [](typename T::ns::type &k) {}; // expected-note 2 {{while substituting into a lambda}}
472   }
473   class S {};
474   void foo() {
475     f(5); // expected-note {{requested here}}
476     f(S()); // expected-note {{requested here}}
477   }
478 }
479 
480 namespace PR21857 {
481   template<typename Fn> struct fun : Fn {
482     fun() = default;
483     using Fn::operator();
484   };
485   template<typename Fn> fun<Fn> wrap(Fn fn);
486   auto x = wrap([](){});
487 }
488 
489 namespace PR13987 {
490 class Enclosing {
491   void Method(char c = []()->char {
492     int d = []()->int {
493         struct LocalClass {
494           int Method() { return 0; }
495         };
496       return 0;
497     }();
498     return d; }()
499   );
500 };
501 }
502 
503 namespace PR23860 {
504 template <class> struct A {
505   void f(int x = []() {
506     struct B {
507       void g() {}
508     };
509     return 0;
510   }());
511 };
512 
513 int main() {
514 }
515 
516 A<int> a;
517 }
518 
519 namespace rdar22032373 {
520 void foo() {
521   auto blk = [](bool b) {
522     if (b)
523       return undeclared_error; // expected-error {{use of undeclared identifier}}
524     return 0;
525   };
526   auto bar = []() {
527     return undef(); // expected-error {{use of undeclared identifier}}
528     return 0; // verify no init_conversion_failed diagnostic emitted.
529   };
530 }
531 }
532 
533 namespace nested_lambda {
534 template <int N>
535 class S {};
536 
537 void foo() {
538   const int num = 18;
539   auto outer = []() {
540     auto inner = [](S<num> &X) {};
541   };
542 }
543 }
544 
545 namespace PR27994 {
546 struct A { template <class T> A(T); };
547 
548 template <class T>
549 struct B {
550   int x;
551   A a = [&] { int y = x; };
552   A b = [&] { [&] { [&] { int y = x; }; }; };
553   A d = [&](auto param) { int y = x; };
554   A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
555 };
556 
557 B<int> b;
558 
559 template <class T> struct C {
560   struct D {
561     int x;
562     A f = [&] { int y = x; };
563   };
564 };
565 
566 int func() {
567   C<int> a;
568   decltype(a)::D b;
569 }
570 }
571 
572 namespace PR30566 {
573 int name1; // expected-note {{'name1' declared here}}
574 
575 struct S1 {
576   template<class T>
577   S1(T t) { s = sizeof(t); }
578   int s;
579 };
580 
581 void foo1() {
582   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
583   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared identifier 'name'; did you mean 'name1'?}}
584 }
585 }
586 
587 namespace PR25627_dont_odr_use_local_consts {
588 
589   template<int> struct X {};
590 
591   void foo() {
592     const int N = 10;
593     (void) [] { X<N> x; };
594   }
595 }
596 
597 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
598   auto x = [](int){};
599   auto y = [](auto &v) -> void { v.n = 0; };
600   using T = decltype(x);
601   using U = decltype(y);
602   using ExpectedTypeT = void (*)(int);
603   template<typename T>
604     using ExpectedTypeU = void (*)(T&);
605 
606   struct X {
607 #if __cplusplus > 201402L
608     friend constexpr auto T::operator()(int) const;
609     friend constexpr T::operator ExpectedTypeT() const noexcept;
610 
611     template<typename T>
612       friend constexpr void U::operator()(T&) const;
613     // FIXME: This should not match; the return type is specified as behaving
614     // "as if it were a decltype-specifier denoting the return type of
615     // [operator()]", which is not equivalent to this alias template.
616     template<typename T>
617       friend constexpr U::operator ExpectedTypeU<T>() const noexcept;
618 #else
619     friend auto T::operator()(int) const;
620     friend T::operator ExpectedTypeT() const;
621 
622     template<typename T>
623       friend void U::operator()(T&) const;
624     // FIXME: This should not match, as above.
625     template<typename T>
626       friend U::operator ExpectedTypeU<T>() const;
627 #endif
628 
629   private:
630     int n;
631   };
632 
633   // Should be OK: lambda's call operator is a friend.
634   void use(X &x) { y(x); }
635 
636   // This used to crash in return type deduction for the conversion opreator.
637   struct A { int n; void f() { +[](decltype(n)) {}; } };
638 }
639 
640 namespace TypoCorrection {
641 template <typename T> struct X {};
642 // expected-note@-1 {{template parameter is declared here}}
643 
644 template <typename T>
645 void Run(const int& points) {
646 // expected-note@-1 {{'points' declared here}}
647   auto outer_lambda = []() {
648     auto inner_lambda = [](const X<Points>&) {};
649     // expected-error@-1 {{use of undeclared identifier 'Points'; did you mean 'points'?}}
650     // expected-error@-2 {{template argument for template type parameter must be a type}}
651   };
652 }
653 }
654 
655 void operator_parens() {
656   [&](int x){ operator()(); }(0); // expected-error {{undeclared 'operator()'}}
657 }
658 
659 namespace captured_name {
660 void Test() {
661   union {           // expected-note {{'' declared here}}
662     int i;
663   };
664   [] { return i; }; // expected-error {{variable '' cannot be implicitly captured in a lambda with no capture-default specified}}
665                     // expected-note@-1 {{lambda expression begins here}}
666                     // expected-note@-2 2 {{default capture by}}
667 }
668 };
669 
670 namespace GH60518 {
671 // Lambdas should not try to capture
672 // function parameters that are used in enable_if
673 struct StringLiteral {
674 template <int N>
675 StringLiteral(const char (&array)[N])
676     __attribute__((enable_if(__builtin_strlen(array) == 2,
677                               "invalid string literal")));
678 };
679 
680 namespace cpp_attribute {
681 struct StringLiteral {
682 template <int N>
683 StringLiteral(const char (&array)[N]) [[clang::annotate_type("test", array)]];
684 };
685 }
686 
687 void Func1() {
688   [[maybe_unused]] auto y = [&](decltype(StringLiteral("xx"))) {};
689   [[maybe_unused]] auto z = [&](decltype(cpp_attribute::StringLiteral("xx"))) {};
690 }
691 
692 }
693 
694 #if __cplusplus > 201402L
695 namespace GH60936 {
696 struct S {
697   int i;
698   // `&i` in default initializer causes implicit `this` access.
699   int *p = &i;
700 };
701 
702 static_assert([]() constexpr {
703   S r = S{2};
704   return r.p != nullptr;
705 }());
706 } // namespace GH60936
707 #endif
708 
709 // Call operator attributes refering to a variable should
710 // be properly handled after D124351
711 constexpr int i = 2;
712 void foo() {
713   (void)[=][[gnu::aligned(i)]] () {}; // expected-warning{{C++23 extension}}
714   // CHECK: AlignedAttr
715   // CHECK-NEXT: ConstantExpr
716   // CHECK-NEXT: value: Int 2
717 }
718 
719 void GH48527() {
720   auto a = []()__attribute__((b(({ return 0; })))){}; // expected-warning {{unknown attribute 'b' ignored}}
721 }
722 
723 void GH67492() {
724   constexpr auto test = 42;
725   auto lambda = (test, []() noexcept(true) {});
726 }
727