blob: 0f3e9481a72207b40e3024b6cdba40e6ae294f9c [file] [log] [blame]
Richard Smith5b013f52013-09-28 05:38:27 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -Wno-c++1y-extensions -std=c++11 %s
Douglas Gregordb0b9f12011-08-04 15:30:47 +00002
3class C {
Richard Smithf44d2a82013-05-21 22:21:19 +00004 id get(int);
Douglas Gregordb0b9f12011-08-04 15:30:47 +00005
6 void f() {
Richard Smithf44d2a82013-05-21 22:21:19 +00007 int foo, bar, baz;
Douglas Gregordb0b9f12011-08-04 15:30:47 +00008
9 // fail to parse as a lambda introducer, so we get objc message parsing errors instead
10 [foo,+] {}; // expected-error {{expected expression}}
11
12 []; // expected-error {{expected body of lambda expression}}
13 [=,foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}}
Richard Smithc084bd282013-02-02 02:14:45 +000014 [&this] {}; // expected-error {{cannot take the address of an rvalue of type 'C *'}}
Douglas Gregor656bc622012-02-09 08:26:42 +000015 [] {};
16 [=] (int i) {};
17 [&] (int) mutable -> void {};
18 [foo,bar] () { return 3; };
19 [=,&foo] () {};
20 [this] () {};
Richard Smith21b3ab42013-05-09 21:36:41 +000021
Richard Smithba71c082013-05-16 06:20:58 +000022 [foo(bar)] () {};
23 [foo = bar] () {};
Richard Smith42b10572015-11-11 01:36:17 +000024 [foo{bar}] () {};
Richard Smithba71c082013-05-16 06:20:58 +000025 [foo = {bar}] () {}; // expected-error {{<initializer_list>}}
Richard Smith21b3ab42013-05-09 21:36:41 +000026
27 [foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}}
Richard Smithf44d2a82013-05-21 22:21:19 +000028 [foo(bar), baz] () {}; // ok
Richard Smith21b3ab42013-05-09 21:36:41 +000029
Richard Smithf44d2a82013-05-21 22:21:19 +000030 [foo = bar baz]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}
31
32 [get(bar) baz]; // expected-warning {{instance method '-baz'}}
33 [get(bar), baz]; // expected-error {{expected body of lambda}}
34
35 [foo = bar ++ baz]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}
36 [foo = bar + baz]; // expected-error {{expected body of lambda}}
37 [foo = { bar, baz }]; // expected-error {{<initializer_list>}} expected-error {{expected body of lambda}}
38 [foo = { bar } baz ]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}
39 [foo = { bar }, baz ]; // expected-error {{<initializer_list>}} expected-error {{expected body of lambda}}
Douglas Gregordb0b9f12011-08-04 15:30:47 +000040 }
41
42};
43
Ben Langmuirc861f412015-04-30 18:40:23 +000044struct Func {
45 template <typename F>
46 Func(F&&);
47};
48
49int getInt();
50
51void test() {
52 [val = getInt()]() { };
53 Func{
54 [val = getInt()]() { }
55 };
56}