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 | 24af85047046f23f1f4cb18a7bdf7240490b921e (patch) | |
tree | 6d9d938b3f86be6c7516c34d7b295eda2dd8729c /clang/test/SemaCXX/lambda-expressions.cpp | |
parent | f798a0a0e69b3c555f12624b0eda3c73694351a7 (diff) | |
download | bcm5719-llvm-24af85047046f23f1f4cb18a7bdf7240490b921e.tar.gz bcm5719-llvm-24af85047046f23f1f4cb18a7bdf7240490b921e.zip |
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.
llvm-svn: 149718
Diffstat (limited to 'clang/test/SemaCXX/lambda-expressions.cpp')
-rw-r--r-- | clang/test/SemaCXX/lambda-expressions.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp index a2dc7070dc4..0f7d5484a8a 100644 --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/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}} + } +} |