Eli Friedman | b942cb2 | 2012-02-03 22:47:37 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify -fblocks %s |
Eli Friedman | e81d7e9 | 2012-01-07 01:08:17 +0000 | [diff] [blame] | 2 | |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 3 | namespace std { class type_info; }; |
| 4 | |
Eli Friedman | e81d7e9 | 2012-01-07 01:08:17 +0000 | [diff] [blame] | 5 | namespace ExplicitCapture { |
Eli Friedman | e81d7e9 | 2012-01-07 01:08:17 +0000 | [diff] [blame] | 6 | class C { |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 7 | int Member; |
Eli Friedman | e81d7e9 | 2012-01-07 01:08:17 +0000 | [diff] [blame] | 8 | |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 9 | static void Overload(int); |
| 10 | void Overload(); |
| 11 | virtual C& Overload(float); |
| 12 | |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 13 | void ImplicitThisCapture() { |
| 14 | [](){(void)Member;}; // expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}} |
| 15 | [&](){(void)Member;}; // expected-error {{not supported yet}} |
Douglas Gregor | a1f2114 | 2012-02-01 17:04:21 +0000 | [diff] [blame] | 16 | // 'this' captures below don't actually work yet |
| 17 | [this](){(void)Member;}; // expected-error{{lambda expressions are not supported yet}} |
| 18 | [this]{[this]{};}; // expected-error 2{{lambda expressions are not supported yet}} |
Eli Friedman | 72899c3 | 2012-01-07 04:59:52 +0000 | [diff] [blame] | 19 | []{[this]{};};// expected-error {{'this' cannot be implicitly captured in this context}} expected-error 2 {{not supported yet}} |
| 20 | []{Overload(3);}; // expected-error {{not supported yet}} |
| 21 | []{Overload();}; // expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}} |
| 22 | []{(void)typeid(Overload());};// expected-error {{not supported yet}} |
| 23 | []{(void)typeid(Overload(.5f));};// expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}} |
| 24 | } |
Eli Friedman | e81d7e9 | 2012-01-07 01:08:17 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | void f() { |
Douglas Gregor | a1f2114 | 2012-02-01 17:04:21 +0000 | [diff] [blame] | 28 | [this] () {}; // expected-error {{'this' cannot be captured in this context}} expected-error {{not supported yet}} |
Eli Friedman | e81d7e9 | 2012-01-07 01:08:17 +0000 | [diff] [blame] | 29 | } |
| 30 | } |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 31 | |
| 32 | namespace ReturnDeduction { |
| 33 | void test() { |
| 34 | [](){ return 1; }; // expected-error {{not supported yet}} |
| 35 | [](){ return 1; }; // expected-error {{not supported yet}} |
| 36 | [](){ return ({return 1; 1;}); }; // expected-error {{not supported yet}} |
| 37 | [](){ return ({return 'c'; 1;}); }; // expected-error {{not supported yet}} expected-error {{must match previous return type}} |
| 38 | []()->int{ return 'c'; return 1; }; // expected-error {{not supported yet}} |
| 39 | [](){ return 'c'; return 1; }; // expected-error {{not supported yet}} expected-error {{must match previous return type}} |
Eli Friedman | e41b041 | 2012-01-26 03:16:41 +0000 | [diff] [blame] | 40 | []() { return; return (void)0; }; // expected-error {{not supported yet}} |
Eli Friedman | 84b007f | 2012-01-26 03:00:14 +0000 | [diff] [blame] | 41 | // FIXME: Need to check structure of lambda body |
| 42 | [](){ return 1; return 1; }; // expected-error {{not supported yet}} |
| 43 | } |
| 44 | } |
Eli Friedman | b942cb2 | 2012-02-03 22:47:37 +0000 | [diff] [blame^] | 45 | |
| 46 | namespace ImplicitCapture { |
| 47 | void test() { |
| 48 | int a = 0; // expected-note 3 {{declared}} |
| 49 | []() { return a; }; // expected-error {{variable 'a' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{begins here}} expected-error {{not supported yet}} |
| 50 | [&]() { return a; }; // expected-error {{not supported yet}} |
| 51 | [=]() { return a; }; // expected-error {{not supported yet}} |
| 52 | [=]() { int* b = &a; }; // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const int *'}} expected-error {{not supported yet}} |
| 53 | [=]() { return [&]() { return a; }; }; // expected-error 2 {{not supported yet}} |
| 54 | []() { return [&]() { return a; }; }; // expected-error {{variable 'a' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} expected-error 2 {{not supported yet}} |
| 55 | []() { return ^{ return a; }; };// expected-error {{variable 'a' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} expected-error {{not supported yet}} |
| 56 | |
| 57 | const int b = 2; |
| 58 | []() { return b; }; // expected-error {{not supported yet}} |
| 59 | |
| 60 | union { // expected-note {{declared}} |
| 61 | int c; |
| 62 | float d; |
| 63 | }; |
| 64 | d = 3; |
| 65 | [=]() { return c; }; // expected-error {{unnamed variable cannot be implicitly captured in a lambda expression}} expected-error {{not supported yet}} |
| 66 | |
| 67 | __block int e; // expected-note {{declared}} |
| 68 | [&]() { return e; }; // expected-error {{__block variable 'e' cannot be captured in a lambda expression}} expected-error {{not supported yet}} |
| 69 | |
| 70 | int f[10]; // expected-note {{declared}} |
| 71 | [&]() { return f[2]; }; // expected-error {{not supported yet}} |
| 72 | (void) ^{ return []() { return f[2]; }; }; // expected-error {{cannot refer to declaration with an array type inside block}} expected-error {{not supported yet}} |
| 73 | |
| 74 | struct G { G(); G(G&); int a; }; // expected-note 6 {{not viable}} |
| 75 | G g; |
| 76 | [=]() { const G* gg = &g; return gg->a; }; // expected-error {{not supported yet}} |
| 77 | [=]() { return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error {{no matching constructor for initialization of 'const ImplicitCapture::G'}} expected-error 2 {{not supported yet}} |
| 78 | (void)^{ return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error 2 {{no matching constructor for initialization of 'const ImplicitCapture::G'}} expected-error {{not supported yet}} |
| 79 | } |
| 80 | } |