lambda-expressions.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
  2. namespace std { class type_info; };
  3. namespace ExplicitCapture {
  4. int GlobalVar; // expected-note {{declared here}}
  5. namespace N {
  6. int AmbiguousVar; // expected-note {{candidate}}
  7. }
  8. int AmbiguousVar; // expected-note {{candidate}}
  9. using namespace N;
  10. class C {
  11. int Member;
  12. static void Overload(int);
  13. void Overload();
  14. virtual C& Overload(float);
  15. void ExplicitCapture() {
  16. int foo;
  17. [foo, foo] () {}; // expected-error {{'foo' can appear only once}} expected-error {{not supported yet}}
  18. [this, this] () {}; // expected-error {{'this' can appear only once}} expected-error {{not supported yet}}
  19. [=, foo] () {}; // expected-error {{'&' must precede a capture when}} expected-error {{not supported yet}}
  20. [=, &foo] () {}; // expected-error {{not supported yet}}
  21. [=, this] () {}; // expected-error {{'this' cannot appear}} expected-error {{not supported yet}}
  22. [&, foo] () {}; // expected-error {{not supported yet}}
  23. [&, &foo] () {}; // expected-error {{'&' cannot precede a capture when}} expected-error {{not supported yet}}
  24. [&, this] () {}; // expected-error {{not supported yet}}
  25. [&Overload] () {}; // expected-error {{does not name a variable}} expected-error {{not supported yet}}
  26. [&GlobalVar] () {}; // expected-error {{does not have automatic storage duration}} expected-error {{not supported yet}}
  27. [&AmbiguousVar] () {} // expected-error {{reference to 'AmbiguousVar' is ambiguous}} expected-error {{not supported yet}}
  28. [&Globalvar] () {}; // expected-error {{use of undeclared identifier 'Globalvar'; did you mean 'GlobalVar}}
  29. }
  30. void ImplicitThisCapture() {
  31. [](){(void)Member;}; // expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}}
  32. [&](){(void)Member;}; // expected-error {{not supported yet}}
  33. [this](){(void)Member;}; // expected-error {{not supported yet}}
  34. [this]{[this]{};};// expected-error 2 {{not supported yet}}
  35. []{[this]{};};// expected-error {{'this' cannot be implicitly captured in this context}} expected-error 2 {{not supported yet}}
  36. []{Overload(3);}; // expected-error {{not supported yet}}
  37. []{Overload();}; // expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}}
  38. []{(void)typeid(Overload());};// expected-error {{not supported yet}}
  39. []{(void)typeid(Overload(.5f));};// expected-error {{'this' cannot be implicitly captured in this context}} expected-error {{not supported yet}}
  40. }
  41. };
  42. void f() {
  43. [this] () {}; // expected-error {{invalid use of 'this'}} expected-error {{not supported yet}}
  44. }
  45. }
  46. namespace ReturnDeduction {
  47. void test() {
  48. [](){ return 1; }; // expected-error {{not supported yet}}
  49. [](){ return 1; }; // expected-error {{not supported yet}}
  50. [](){ return ({return 1; 1;}); }; // expected-error {{not supported yet}}
  51. [](){ return ({return 'c'; 1;}); }; // expected-error {{not supported yet}} expected-error {{must match previous return type}}
  52. []()->int{ return 'c'; return 1; }; // expected-error {{not supported yet}}
  53. [](){ return 'c'; return 1; }; // expected-error {{not supported yet}} expected-error {{must match previous return type}}
  54. // FIXME: Need to check structure of lambda body
  55. [](){ return 1; return 1; }; // expected-error {{not supported yet}}
  56. }
  57. }