1 // RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
2 
3 namespace misplaced_capture_default {
Test()4 void Test() {
5   int i = 0;
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}}
10 
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}}
14   [=, &i] {};  // ok
15   [&, &i] {};  // expected-error {{'&' cannot precede a capture when the capture default is '&'}}
16   [&x = i] {}; // ok
17   [=, &x = i] {};  // ok
18   [x = &i] {};     // ok
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}}
21 
22   [i, &, x = 2] {}; // expected-error {{capture default must be first}}
23   [i, =, x = 2] {}; // expected-error {{capture default must be first}}
24 }
25 } // namespace misplaced_capture_default
26 
27 namespace misplaced_capture_default_pack {
Test(Args...args)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}}
37 }
38 } // namespace misplaced_capture_default_pack
39