1 // RUN: %clang_cc1 -std=c++1y %s -verify -emit-llvm-only
2 // RUN: %clang_cc1 -std=c++1z %s -verify -emit-llvm-only
4 namespace variadic_expansion
{
5 int f(int &, char &) { return 0; }
6 template<class ... Ts
> char fv(Ts
... ts
) { return 0; }
7 // FIXME: why do we get 2 error messages
8 template <typename
... T
> void g(T
&... t
) { //expected-note3{{declared here}}
9 f([&a(t
)]()->decltype(auto) {
13 auto L
= [x
= f([&a(t
)]()->decltype(auto) { return a
; }()...)]() { return x
; };
16 &z
= y
](T
& ... t
) { };
19 o
= f([&a(t
)](T
& ... t
)->decltype(auto) { return a
; }(t
...)...), t
...](T
& ... s
) {
20 fv([&a(t
)]()->decltype(auto) {
24 auto N2
= [x
= y
, //expected-note3{{begins here}} expected-note 6 {{default capture by}}
26 o
= f([&a(t
)](T
& ... t
)->decltype(auto) { return a
; }(t
...)...)](T
& ... s
) { // expected-note 6 {{capture 't' by}}
27 fv([&a(t
)]()->decltype(auto) { //expected-error 3{{captured}}
34 void h(int i
, char c
) { g(i
, c
); } //expected-note{{in instantiation}}
37 namespace odr_use_within_init_capture
{
43 auto L
= [z
= x
+ 2](int a
) {
44 auto M
= [y
= x
- 2](char b
) {
51 { // should not capture
53 auto L
= [&z
= x
](int a
) {
60 auto L
= [k
= x
](char a
) { //expected-note {{declared}}
61 return [](int b
) { //expected-note {{begins}} expected-note 2 {{capture 'k' by}} expected-note 2 {{default capture by}}
62 return [j
= k
](int c
) { //expected-error {{cannot be implicitly captured}}
70 auto L
= [k
= x
](char a
) {
72 return [j
= k
](int c
) {
80 auto L
= [k
= x
](char a
) {
82 return [j
= k
](int c
) {
96 namespace odr_use_within_init_capture_template
{
98 template<class T
= int>
103 auto L
= [z
= x
](char a
) {
104 auto M
= [y
= x
](T b
) {
111 { // should not capture
113 auto L
= [&z
= x
](T a
) {
118 { // will need to capture x in outer lambda
119 const T x
= 10; //expected-note {{declared}}
120 auto L
= [z
= x
](char a
) { //expected-note {{begins}} expected-note 2 {{capture 'x' by}} expected-note 2 {{default capture by}}
121 auto M
= [&y
= x
](T b
) { //expected-error {{cannot be implicitly captured}}
127 { // will need to capture x in outer lambda
129 auto L
= [=,z
= x
](char a
) {
130 auto M
= [&y
= x
](T b
) {
137 { // will need to capture x in outer lambda
139 auto L
= [x
, z
= x
](char a
) {
140 auto M
= [&y
= x
](T b
) {
146 { // will need to capture x in outer lambda
147 const int x
= 10; //expected-note {{declared}}
148 auto L
= [z
= x
](char a
) { //expected-note {{begins}} expected-note 2 {{capture 'x' by}} expected-note 2 {{default capture by}}
149 auto M
= [&y
= x
](T b
) { //expected-error {{cannot be implicitly captured}}
159 [z
= x
, &y
= x
](char a
) { return z
+ y
; }('a')](char a
)
167 int run
= test(); //expected-note {{instantiation}}
171 namespace classification_of_captures_of_init_captures
{
173 template <typename T
>
175 [a
= 24] () mutable {
180 template <typename T
>
182 [a
= 24] (auto param
) mutable {
195 struct X
{ X(); explicit X(const X
&); int n
; };
196 auto a
= [x
{X()}] { return x
.n
; }; // ok
197 auto b
= [x
= {X()}] {}; // expected-error{{<initializer_list>}}
200 namespace init_capture_non_mutable
{
201 void test(double weight
) {
203 auto find
= [max
= init
](auto current
) {
204 max
= current
; // expected-error{{cannot assign to a variable captured by copy in a non-mutable lambda}}
206 find(weight
); // expected-note {{in instantiation of function template specialization}}
210 namespace init_capture_undeclared_identifier
{
211 auto a
= [x
= y
]{}; // expected-error{{use of undeclared identifier 'y'}}
213 int typo_foo
; // expected-note 2 {{'typo_foo' declared here}}
214 auto b
= [x
= typo_boo
]{}; // expected-error{{use of undeclared identifier 'typo_boo'; did you mean 'typo_foo'}}
215 auto c
= [x(typo_boo
)]{}; // expected-error{{use of undeclared identifier 'typo_boo'; did you mean 'typo_foo'}}
218 namespace copy_evasion
{
221 A(const A
&) = delete;
223 auto x
= [a
{A()}] {};
224 #if __cplusplus >= 201702L
225 // ok, does not copy an 'A'
227 // expected-error@-4 {{call to deleted}}
228 // expected-note@-7 {{deleted}}