1 // RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
3 namespace misplaced_capture_default
{
6 [&, i
, &] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
7 [&, i
, = ] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
8 [=, &i
, &] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
9 [=, &i
, = ] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
11 [i
, &] {}; // expected-error {{capture default must be first}}
12 [i
, = ] {}; // expected-error {{capture default must be first}}
13 [i
, = x
] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
15 [&, &i
] {}; // expected-error {{'&' cannot precede a capture when the capture default is '&'}}
19 [=, &x
= &i
] {}; // expected-error {{non-const lvalue reference to type 'int *' cannot bind to a temporary of type 'int *'}}
20 [&, this] {}; // expected-error {{'this' cannot be captured in this context}}
22 [i
, &, x
= 2] {}; // expected-error {{capture default must be first}}
23 [i
, =, x
= 2] {}; // expected-error {{capture default must be first}}
25 } // namespace misplaced_capture_default
27 namespace misplaced_capture_default_pack
{
28 template <typename
... Args
> void Test(Args
... args
) {
29 [&, args
...] {}; // ok
30 [args
..., &] {}; // expected-error {{capture default must be first}}
31 [=, &args
...] {}; // ok
32 [&, ... xs
= &args
] {}; // ok
33 [&, ... xs
= &] {}; // expected-error {{expected expression}}
34 [... xs
= &] {}; // expected-error {{expected expression}}
35 [... xs
= &args
, = ] {}; // expected-error {{capture default must be first}}
36 [... xs
= &args
, &] {}; // expected-error {{capture default must be first}}
38 } // namespace misplaced_capture_default_pack