aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/lambda-expressions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/lambda-expressions.cpp')
-rw-r--r--test/SemaCXX/lambda-expressions.cpp38
1 files changed, 37 insertions, 1 deletions
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}}
+ }
+}