p4-0x.cpp 672 B

12345678910111213141516171819202122
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. struct S {
  3. S *p = this; // ok
  4. decltype(this) q; // expected-error {{invalid use of 'this' outside of a non-static member function}}
  5. int arr[sizeof(this)]; // expected-error {{invalid use of 'this' outside of a non-static member function}}
  6. int sz = sizeof(this); // ok
  7. typedef auto f() -> decltype(this); // expected-error {{invalid use of 'this' outside of a non-static member function}}
  8. };
  9. namespace CaptureThis {
  10. struct X {
  11. int n = 10;
  12. int m = [&]{return n + 1; }();
  13. int o = [&]{return this->m + 1; }();
  14. int p = [&]{return [&](int x) { return this->m + x;}(o); }();
  15. };
  16. X x;
  17. }