48 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s2 3namespace misplaced_capture_default {4void 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] {}; // ok15 [&, &i] {}; // expected-error {{'&' cannot precede a capture when the capture default is '&'}}16 [&x = i] {}; // ok17 [=, &x = i] {}; // ok18 [x = &i] {}; // ok19 [=, &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_default26 27namespace misplaced_capture_default_pack {28template <typename... Args> void Test(Args... args) {29 [&, args...] {}; // ok30 [args..., &] {}; // expected-error {{capture default must be first}}31 [=, &args...] {}; // ok32 [&, ... xs = &args] {}; // ok33 [&, ... 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_pack39 40namespace GH163498 {41struct S {42 template <class T> S(T) {}43};44void t() {45 S s{[a(42), &] {}}; // expected-error {{capture default must be first}}46}47}48