diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-08-04 15:30:47 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-08-04 15:30:47 +0000 |
commit | db0b9f12645992bf730b3230efa3bd79a6a98b1b (patch) | |
tree | 193a2ad1146d1ac9fbe4619892f8b783fce44ae6 /clang/test | |
parent | 96df560ce1224abca26d3a7785de63766f40a01a (diff) | |
download | bcm5719-llvm-db0b9f12645992bf730b3230efa3bd79a6a98b1b.tar.gz bcm5719-llvm-db0b9f12645992bf730b3230efa3bd79a6a98b1b.zip |
Parsing of C++0x lambda expressions, from John Freeman with help from
David Blaikie!
llvm-svn: 136876
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Parser/cxx0x-attributes.cpp | 2 | ||||
-rw-r--r-- | clang/test/Parser/cxx0x-lambda-expressions.cpp | 27 | ||||
-rw-r--r-- | clang/test/Parser/objc-messaging-neg-1.m | 1 | ||||
-rw-r--r-- | clang/test/Parser/objcxx-lambda-expressions-neg.mm | 5 | ||||
-rw-r--r-- | clang/test/Parser/objcxx0x-lambda-expressions.mm | 26 |
5 files changed, 60 insertions, 1 deletions
diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index f65e2907095..0285ee1e9ac 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -17,7 +17,7 @@ int comma_attr [[,]]; // expected-error {{expected identifier}} int scope_attr [[foo::]]; // expected-error {{expected identifier}} int & [[]] ref_attr = after_attr; // expected-error {{an attribute list cannot appear here}} class foo { - void after_const_attr () const [[]]; // expected-error {{expected expression}} + void after_const_attr () const [[]]; // expected-error {{expected body of lambda expression}} expected-error {{array has incomplete element type 'void'}} }; extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} [[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}} diff --git a/clang/test/Parser/cxx0x-lambda-expressions.cpp b/clang/test/Parser/cxx0x-lambda-expressions.cpp new file mode 100644 index 00000000000..54281e30826 --- /dev/null +++ b/clang/test/Parser/cxx0x-lambda-expressions.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +class C { + + int f() { + int foo, bar; + + []; // expected-error {{expected body of lambda expression}} + [+] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} + [foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}} + [foo,&this] {}; // expected-error {{'this' cannot be captured by reference}} + [&this] {}; // expected-error {{'this' cannot be captured by reference}} + [&,] {}; // expected-error {{ expected variable name or 'this' in lambda capture list}} + [=,] {}; // expected-error {{ expected variable name or 'this' in lambda capture list}} + [] {}; + [=] (int i) {}; + [&] (int) mutable -> void {}; + [foo,bar] () { return 3; }; + [=,&foo] () {}; + [&,foo] () {}; + [this] () {}; + + return 1; + } + +}; + diff --git a/clang/test/Parser/objc-messaging-neg-1.m b/clang/test/Parser/objc-messaging-neg-1.m index 4ddadb816f0..bb496e96914 100644 --- a/clang/test/Parser/objc-messaging-neg-1.m +++ b/clang/test/Parser/objc-messaging-neg-1.m @@ -9,4 +9,5 @@ int main() { [a bla:0 6:7]; // expected-error {{expected ']'}} [A foo bar]; // expected-error {{expected ':'}} [A foo bar bar1]; // expected-error {{expected ':'}} + [] {}; // expected-error {{expected expression}} } diff --git a/clang/test/Parser/objcxx-lambda-expressions-neg.mm b/clang/test/Parser/objcxx-lambda-expressions-neg.mm new file mode 100644 index 00000000000..864cc6b8fbf --- /dev/null +++ b/clang/test/Parser/objcxx-lambda-expressions-neg.mm @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +int main() { + []{}; // expected-error {{expected expression}} +} diff --git a/clang/test/Parser/objcxx0x-lambda-expressions.mm b/clang/test/Parser/objcxx0x-lambda-expressions.mm new file mode 100644 index 00000000000..d100e2e4880 --- /dev/null +++ b/clang/test/Parser/objcxx0x-lambda-expressions.mm @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +class C { + + void f() { + int foo, bar; + + // fail to parse as a lambda introducer, so we get objc message parsing errors instead + [foo,+] {}; // expected-error {{expected expression}} + + []; // expected-error {{expected body of lambda expression}} + [=,foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}} + [&this] {}; // expected-error {{address expression must be an lvalue}} + [] {}; + [=] (int i) {}; + [&] (int) mutable -> void {}; + // FIXME: this error occurs because we do not yet handle lambda scopes + // properly. I did not anticipate it because I thought it was a semantic (not + // syntactic) check. + [foo,bar] () { return 3; }; // expected-error {{void function 'f' should not return a value}} + [=,&foo] () {}; + [this] () {}; + } + +}; + |