John McCall | 32509f1 | 2011-11-15 01:35:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
Douglas Gregor | 5e6fcd4 | 2011-02-08 02:14:35 +0000 | [diff] [blame] | 2 | |
| 3 | struct X { |
| 4 | void f() const; |
| 5 | ~X(); |
| 6 | }; |
| 7 | |
| 8 | @interface A { |
| 9 | X x_; |
| 10 | } |
| 11 | |
| 12 | - (const X&)x; |
| 13 | - (void)setx:(const X&)other; |
| 14 | @end |
| 15 | |
| 16 | @implementation A |
| 17 | |
| 18 | - (const X&)x { return x_; } |
| 19 | - (void)setx:(const X&)other { x_ = other; } |
| 20 | - (void)method { |
| 21 | self.x.f(); |
John McCall | 32509f1 | 2011-11-15 01:35:18 +0000 | [diff] [blame] | 22 | } |
Douglas Gregor | 5e6fcd4 | 2011-02-08 02:14:35 +0000 | [diff] [blame] | 23 | @end |
| 24 | |
John McCall | 32509f1 | 2011-11-15 01:35:18 +0000 | [diff] [blame] | 25 | // rdar://problem/10444030 |
| 26 | @interface Test2 |
| 27 | - (void) setY: (int) y; |
| 28 | - (int) z; |
| 29 | @end |
| 30 | void test2(Test2 *a) { |
| 31 | auto y = a.y; // expected-error {{expected getter method not found on object of type 'Test2 *'}} expected-error {{variable 'y' with type 'auto' has incompatible initializer of type}} |
| 32 | auto z = a.z; |
| 33 | } |
John McCall | 806054d | 2012-01-11 00:14:46 +0000 | [diff] [blame] | 34 | |
| 35 | // rdar://problem/10672108 |
| 36 | @interface Test3 |
| 37 | - (int) length; |
| 38 | @end |
| 39 | void test3(Test3 *t) { |
John McCall | 52f220d | 2012-01-11 01:35:55 +0000 | [diff] [blame] | 40 | char vla[t.length] = {}; // expected-error {{variable-sized object may not be initialized}} |
| 41 | char *heaparray = new char[t.length]; |
John McCall | 806054d | 2012-01-11 00:14:46 +0000 | [diff] [blame] | 42 | } |
Eli Friedman | ed0b31f | 2012-01-12 00:44:34 +0000 | [diff] [blame^] | 43 | |
| 44 | @interface Test4 |
| 45 | - (X&) prop; |
| 46 | @end |
| 47 | void test4(Test4 *t) { |
| 48 | (void)const_cast<const X&>(t.prop); |
| 49 | (void)dynamic_cast<X&>(t.prop); |
| 50 | (void)reinterpret_cast<int&>(t.prop); |
| 51 | } |