blob: 54b2ff52895a0a87bf3345af3d6fbf3136af2761 [file] [log] [blame]
Richard Smith9ca5c422011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Richard Smith938f40b2011-06-11 17:19:42 +00002
3struct S {
4 S *p = this; // ok
Richard Smithfa0a1f52012-04-05 01:13:04 +00005 decltype(this) q; // expected-error {{invalid use of 'this' outside of a non-static member function}}
Richard Smith938f40b2011-06-11 17:19:42 +00006
Richard Smithfa0a1f52012-04-05 01:13:04 +00007 int arr[sizeof(this)]; // expected-error {{invalid use of 'this' outside of a non-static member function}}
Richard Smith938f40b2011-06-11 17:19:42 +00008 int sz = sizeof(this); // ok
Richard Smith990a6922014-01-17 21:01:18 +00009
10 typedef auto f() -> decltype(this); // expected-error {{invalid use of 'this' outside of a non-static member function}}
Richard Smith938f40b2011-06-11 17:19:42 +000011};
Douglas Gregorb8389972012-02-21 22:51:27 +000012
13namespace CaptureThis {
14 struct X {
15 int n = 10;
16 int m = [&]{return n + 1; }();
17 int o = [&]{return this->m + 1; }();
18 int p = [&]{return [&](int x) { return this->m + x;}(o); }();
19 };
20
21 X x;
22}