This is a small start based on a run-through of the FDIS.
Some errors seem poorly diagnosed in the revision I used (b09ab8c on the
Git mirror; I believe after r151076 in the Subversion repo). I wrote the
tests as I would like to see them diagnosed instead of how they are
currently, so those show up as unexpected failures.
A missing feature (specifically conversion to function-to-pointer) also
appears as an unexpected failure.
Please let me know what other tests would be desired, and I'll write
them up. Please also point out any mistakes I made with these tests. I
want to make sure they conform to Clang's standards.
- John
diff --git test/Parser/cxx0x-lambda-expressions.cpp
test/Parser/cxx0x-lambda-expressions.cpp
index 87d1405..3863487 100644
--- test/Parser/cxx0x-lambda-expressions.cpp
+++ test/Parser/cxx0x-lambda-expressions.cpp
@@ -19,6 +19,9 @@ class C {
[=,&foo] () {};
[&,foo] () {};
[this] () {};
+ [=,a] {}; // expected-error {{'&' must precede a capture when the capture
default is '='}}
+ [=,this]{}; // expected-error {{'this' cannot be explicitly captured when
the capture default is '='}}
+ [&,&a] {}; // expected-error {{'&' cannot precede a capture when the
capture default is '&'}}
[] -> int { return 0; }; // expected-error{{lambda requires '()' before
return type}}
[] mutable -> int { return 0; }; // expected-error{{lambda requires '()'
before 'mutable'}}
diff --git test/SemaCXX/lambda-expressions.cpp
test/SemaCXX/lambda-expressions.cpp
index 1358d9e..07d6149 100644
--- test/SemaCXX/lambda-expressions.cpp
+++ test/SemaCXX/lambda-expressions.cpp
@@ -2,6 +2,11 @@
namespace std { class type_info; };
+namespace UnevaluatedContexts {
+ decltype([]{}) a; // expected-error {{lambda expression in an unevaluated
operand}}
+ noexcept([]{}); // expected-error {{lambda expression in an unevaluated
operand}}
+}
+
namespace ExplicitCapture {
class C {
int Member;
@@ -16,7 +21,7 @@ namespace ExplicitCapture {
[this](){(void)Member;};
[this]{[this]{};};
- []{[this]{};};// expected-error {{'this' cannot be implicitly captured
in this context}}
+ []{[this]{};}; // expected-error {{'this' cannot be implicitly captured
in this context}}
[]{Overload(3);};
[]{Overload();}; // expected-error {{'this' cannot be implicitly
captured in this context}}
[]{(void)typeid(Overload());};
@@ -38,17 +43,19 @@ namespace ReturnDeduction {
// expected-warning{{omitted result type}}
[]()->int{ return 'c'; return 1; };
[](){ return 'c'; return 1; }; // expected-error {{must match previous
return type}}
- []() { return; return (void)0; };
+ [](){ return; return (void)0; };
[](){ return 1; return 1; }; // expected-warning{{omitted result type}}
+ [](){ return {1, 2}; }; // expected-error {{cannot deduce lambda return
type}}
}
}
namespace ImplicitCapture {
- void test() {
- int a = 0; // expected-note 5 {{declared}}
+ void test(int j) {
+ int a = 0; // expected-note 6 {{declared}}
[]() { return a; }; // expected-error {{variable 'a' cannot be implicitly
captured in a lambda with no capture-default specified}} expected-note {{begins
here}}
[&]() { return a; };
[=]() { return a; };
+ struct C { void foo() { [&]{a;}; } }; // expected-error {{local variable
'a' declared in enclosing}}
[=]() { int* b = &a; }; // expected-error {{cannot initialize a variable
of type 'int *' with an rvalue of type 'const int *'}}
[=]() { return [&]() { return a; }; };
[]() { 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}}
@@ -85,6 +92,8 @@ namespace ImplicitCapture {
const int h = a; // expected-note {{declared}}
[]() { return h; }; // expected-error {{variable 'h' cannot be implicitly
captured in a lambda with no capture-default specified}} expected-note {{lambda
expression begins here}}
+
+ [j]{};
}
}
@@ -101,3 +110,44 @@ namespace PR12031 {
f(v, [](){});
}
}
+
+namespace Mutability {
+ void test() {
+ int a;
+ [=]() { a = 1; }; // expected-error {{read-only variable is not
assignable}}
+ [=]() mutable { a = 1; };
+ [&]() { a = 1; };
+ }
+}
+
+namespace DefaultArguments {
+ void test() {
+ int a = 1;
+ void f1(int = [a]{ return a; }()); // expected-error {{lambda expression
in default argument cannot capture any entity}}
+ void f2(int = [a]{ return 0; }()); // expected-error {{lambda expression
in default argument cannot capture any entity}}
+ void f3(int = [=]{ return a; }()); // expected-error {{lambda expression
in default argument cannot capture any entity}}
+ void f4(int = [=]{ return 0; }());
+ void f5(int = [=]{ return sizeof(a); }());
+ }
+}
+
+namespace Misc {
+ class C;
+
+ void test() {
+ []() -> C* { return 0; };
+
+ typedef float (*ft)(int);
+ ft f1 = [](int a) { return a*2.0; };
+ ft f2 = [=](int a) { return a*2.0; }; // expected-error {{cannot convert
lambda with capture specification to function-to-pointer}}
+
+ auto f3 = []{}; // expected-note 2 {{begins here}}
+ decltype(f3) f4(f3);
+ decltype(f3) f5; // expected-error {{call to implicitly-deleted default
constructor of 'decltype(f3)'}}
+ f4 = f3; // expected-error {{overload resolution selected
implicitly-deleted copy assignment operator}}
+ }
+
+ int b; // expected-note {{declared}}
+ auto f = [b]{}; // expected-error {{'b' cannot be captured because it does
not have automatic storage duration}}
+}
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits