p8.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. // RUN: %clang_cc1 -std=c++11 %s -verify -Wno-c++1y-extensions
  2. class X0 {
  3. void explicit_capture() {
  4. int foo;
  5. (void)[foo, foo] () {}; // expected-error {{'foo' can appear only once}}
  6. (void)[this, this] () {}; // expected-error {{'this' can appear only once}}
  7. (void)[=, foo] () {}; // expected-error {{'&' must precede a capture when}}
  8. (void)[=, &foo] () {};
  9. (void)[=, this] () {}; // expected-error {{'this' cannot be explicitly captured}}
  10. (void)[&, foo] () {};
  11. (void)[&, &foo] () {}; // expected-error {{'&' cannot precede a capture when}}
  12. (void)[&, this] () {};
  13. }
  14. };
  15. struct S2 {
  16. void f(int i);
  17. void g(int i);
  18. };
  19. void S2::f(int i) {
  20. (void)[&, i]{ };
  21. (void)[&, &i]{ }; // expected-error{{'&' cannot precede a capture when the capture default is '&'}}
  22. (void)[=, this]{ }; // expected-error{{'this' cannot be explicitly captured}}
  23. (void)[=]{ this->g(i); };
  24. (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
  25. (void)[i(0), i(1)]{ }; // expected-error{{'i' can appear only once in a capture list}}
  26. (void)[i, i(1)]{ }; // expected-error{{'i' can appear only once in a capture list}}
  27. (void)[i(0), i]{ }; // expected-error{{'i' can appear only once in a capture list}}
  28. }