diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2012-02-03 22:47:37 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2012-02-03 22:47:37 +0000 |
commit | b942cb24a060435b18fef5b43eb33d77afc0d03a (patch) | |
tree | f4284905fbe1487823a4583271eba4de1201b55e /test | |
parent | 285c6070cba54ab9bb1d3bacdc2028498a83baef (diff) |
Implement implicit capture for lambda expressions.
Still left: explicit captures in lambdas need to cause implicit capture, and I need to take a look at the diagnostics for some cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149718 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/CXX/expr/expr.prim/expr.prim.lambda/blocks.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/lambda-expressions.cpp | 38 |
2 files changed, 38 insertions, 3 deletions
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.cpp index faf686d111..2ed738d3fd 100644 --- a/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.cpp +++ b/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.cpp @@ -5,7 +5,6 @@ void block_capture_errors() { (void)[var] { }; // expected-error{{__block variable 'var' cannot be captured in a lambda}} \ // expected-error{{lambda expressions are not supported yet}} - // FIXME: this should produce the same error as above - (void)[=] { var = 17; }; // expected-error{{reference to local variable 'var' declared in enclosed function 'block_capture_errors'}} \ + (void)[=] { var = 17; }; // expected-error{{__block variable 'var' cannot be captured in a lambda}} \ // expected-error{{lambda expressions are not supported yet}} } diff --git a/test/SemaCXX/lambda-expressions.cpp b/test/SemaCXX/lambda-expressions.cpp index a2dc7070dc..0f7d5484a8 100644 --- a/test/SemaCXX/lambda-expressions.cpp +++ b/test/SemaCXX/lambda-expressions.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify -fblocks %s namespace std { class type_info; }; @@ -42,3 +42,39 @@ namespace ReturnDeduction { [](){ return 1; return 1; }; // expected-error {{not supported yet}} } } + +namespace ImplicitCapture { + void test() { + int a = 0; // expected-note 3 {{declared}} + []() { 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}} + [&]() { return a; }; // expected-error {{not supported yet}} + [=]() { return a; }; // expected-error {{not supported yet}} + [=]() { int* b = &a; }; // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const int *'}} expected-error {{not supported yet}} + [=]() { return [&]() { return a; }; }; // expected-error 2 {{not supported yet}} + []() { 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}} + []() { 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}} + + const int b = 2; + []() { return b; }; // expected-error {{not supported yet}} + + union { // expected-note {{declared}} + int c; + float d; + }; + d = 3; + [=]() { return c; }; // expected-error {{unnamed variable cannot be implicitly captured in a lambda expression}} expected-error {{not supported yet}} + + __block int e; // expected-note {{declared}} + [&]() { return e; }; // expected-error {{__block variable 'e' cannot be captured in a lambda expression}} expected-error {{not supported yet}} + + int f[10]; // expected-note {{declared}} + [&]() { return f[2]; }; // expected-error {{not supported yet}} + (void) ^{ return []() { return f[2]; }; }; // expected-error {{cannot refer to declaration with an array type inside block}} expected-error {{not supported yet}} + + struct G { G(); G(G&); int a; }; // expected-note 6 {{not viable}} + G g; + [=]() { const G* gg = &g; return gg->a; }; // expected-error {{not supported yet}} + [=]() { 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}} + (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}} + } +} |