xref: /llvm-project/clang/test/CXX/expr/expr.prim/expr.prim.general/p4-0x.cpp (revision 990a692f4a9251d1fb694768e6c1895b8b8b9945)
1b06c68d3SDavid Blaikie // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2b06c68d3SDavid Blaikie 
3b06c68d3SDavid Blaikie struct S {
4b06c68d3SDavid Blaikie   S *p = this; // ok
5fa0a1f53SRichard Smith   decltype(this) q; // expected-error {{invalid use of 'this' outside of a non-static member function}}
6b06c68d3SDavid Blaikie 
7fa0a1f53SRichard Smith   int arr[sizeof(this)]; // expected-error {{invalid use of 'this' outside of a non-static member function}}
8b06c68d3SDavid Blaikie   int sz = sizeof(this); // ok
9*990a692fSRichard Smith 
10*990a692fSRichard Smith   typedef auto f() -> decltype(this); // expected-error {{invalid use of 'this' outside of a non-static member function}}
11b06c68d3SDavid Blaikie };
12b8389976SDouglas Gregor 
13b8389976SDouglas Gregor namespace CaptureThis {
14b8389976SDouglas Gregor   struct X {
15b8389976SDouglas Gregor     int n = 10;
__anondde04c930102CaptureThis::X16b8389976SDouglas Gregor     int m = [&]{return n + 1; }();
__anondde04c930202CaptureThis::X17b8389976SDouglas Gregor     int o = [&]{return this->m + 1; }();
__anondde04c930302CaptureThis::X18b8389976SDouglas Gregor     int p = [&]{return [&](int x) { return this->m + x;}(o); }();
19b8389976SDouglas Gregor   };
20b8389976SDouglas Gregor 
21b8389976SDouglas Gregor   X x;
22b8389976SDouglas Gregor }
23