Richard Smith | 9ca5c42 | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2 | |
| 3 | struct S { |
| 4 | S *p = this; // ok |
Richard Smith | fa0a1f5 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 5 | decltype(this) q; // expected-error {{invalid use of 'this' outside of a non-static member function}} |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 6 | |
Richard Smith | fa0a1f5 | 2012-04-05 01:13:04 +0000 | [diff] [blame] | 7 | int arr[sizeof(this)]; // expected-error {{invalid use of 'this' outside of a non-static member function}} |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 8 | int sz = sizeof(this); // ok |
Richard Smith | 990a692 | 2014-01-17 21:01:18 +0000 | [diff] [blame] | 9 | |
| 10 | typedef auto f() -> decltype(this); // expected-error {{invalid use of 'this' outside of a non-static member function}} |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 11 | }; |
Douglas Gregor | b838997 | 2012-02-21 22:51:27 +0000 | [diff] [blame] | 12 | |
| 13 | namespace 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 | } |