blob: 36f59b650cec7a0e84e4a3c5c4ace71984604883 [file] [log] [blame]
Patrick Beardacfbe9e2012-04-06 18:12:22 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wno-objc-root-class %s
Douglas Gregora57a66e2011-02-08 02:14:35 +00002
3struct 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 McCalld5c98ae2011-11-15 01:35:18 +000022}
Douglas Gregora57a66e2011-02-08 02:14:35 +000023@end
24
John McCalld5c98ae2011-11-15 01:35:18 +000025// rdar://problem/10444030
26@interface Test2
27- (void) setY: (int) y;
28- (int) z;
29@end
30void test2(Test2 *a) {
Eli Friedmanfd41aee2012-11-29 03:13:49 +000031 auto y = a.y; // expected-error {{no getter method for read from property}}
John McCalld5c98ae2011-11-15 01:35:18 +000032 auto z = a.z;
33}
John McCall9b80c212012-01-11 00:14:46 +000034
35// rdar://problem/10672108
36@interface Test3
37- (int) length;
38@end
39void test3(Test3 *t) {
John McCallfd3b6642012-01-11 01:35:55 +000040 char vla[t.length] = {}; // expected-error {{variable-sized object may not be initialized}}
41 char *heaparray = new char[t.length];
John McCall9b80c212012-01-11 00:14:46 +000042}
Eli Friedman42b199c2012-01-12 00:44:34 +000043
Douglas Gregorbf3a8262012-01-12 16:11:24 +000044// <rdar://problem/10672501>
45namespace std {
46 template<typename T> void count();
Eli Friedman42b199c2012-01-12 00:44:34 +000047}
Douglas Gregorbf3a8262012-01-12 16:11:24 +000048
Douglas Gregorccff3012012-01-13 16:56:26 +000049@interface Test4
50- (X&) prop;
51@end
52
53void test4(Test4 *t) {
54 (void)const_cast<const X&>(t.prop);
55 (void)dynamic_cast<X&>(t.prop);
56 (void)reinterpret_cast<int&>(t.prop);
57}
58
59@interface Test5 {
Douglas Gregorbf3a8262012-01-12 16:11:24 +000060@public
61 int count;
62}
63@property int count;
64@end
65
Douglas Gregorccff3012012-01-13 16:56:26 +000066void test5(Test5* t5) {
67 if (t5.count < 2) { }
68 if (t5->count < 2) { }
Douglas Gregorbf3a8262012-01-12 16:11:24 +000069}
70
Douglas Gregor36107ad2012-02-16 18:19:22 +000071
72@interface Test6
73+ (Class)class;
74- (Class)class;
75@end
76
77void test6(Test6 *t6) {
78 Class x = t6.class;
79 Class x2 = Test6.class;
80}
81
82template<typename T>
83void test6_template(T *t6) {
84 Class x = t6.class;
85}
86
87template void test6_template(Test6*);
John McCallef429022012-03-09 04:08:29 +000088
89// rdar://problem/10965735
90struct Test7PointerMaker {
91 operator char *() const;
92};
93@interface Test7
94- (char*) implicit_property;
95- (char) bad_implicit_property;
96- (Test7PointerMaker) implicit_struct_property;
97@property int *explicit_property;
98@property int bad_explicit_property;
99@property Test7PointerMaker explicit_struct_property;
100@end
101void test7(Test7 *ptr) {
102 delete ptr.implicit_property;
103 delete ptr.bad_implicit_property; // expected-error {{cannot delete expression of type 'char'}}
104 delete ptr.explicit_property;
105 delete ptr.bad_explicit_property; // expected-error {{cannot delete expression of type 'int'}}
106 delete ptr.implicit_struct_property;
107 delete ptr.explicit_struct_property;
108}
Eli Friedman00fa4292012-11-13 23:16:33 +0000109
110// Make sure the returned value from property assignment is void,
111// because there isn't any other viable way to handle it for
112// non-trivial classes.
113class NonTrivial1 {
114public:
115 ~NonTrivial1();
116};
117class NonTrivial2 {
118public:
119 NonTrivial2();
120 NonTrivial2(const NonTrivial2&);
121};
122@interface TestNonTrivial
123@property(assign, nonatomic) NonTrivial1 p1;
124@property(assign, nonatomic) NonTrivial2 p2;
125@end
126TestNonTrivial *TestNonTrivialObj;
127
128extern void* VoidType;
129extern decltype(TestNonTrivialObj.p1 = NonTrivial1())* VoidType;
130extern decltype(TestNonTrivialObj.p2 = NonTrivial2())* VoidType;
131
John McCallf22d0ac2013-03-04 01:30:55 +0000132// rdar://13332183
133namespace test9 {
134 struct CString {
135 const char *_data;
136 char operator[](int i) const { return _data[i]; }
137 };
138}
139@interface Test9
140@property test9::CString name;
141@end
142namespace test9 {
143 char test(Test9 *t) {
144 return t.name[0];
145 }
146}
147
148namespace test10 {
149 struct A { operator const char*(); };
150 struct B { operator const char*(); };
151}
152@interface Test10
153@property test10::A a;
154@property test10::B b;
155@property int index;
156@end
157namespace test10 {
158 void test(Test10 *t) {
159 (void) t.a[6];
160 (void) 6[t.b];
161 (void) "help"[t.index];
162 (void) t.index["help"];
163 (void) t.a[t.index];
164 (void) t.index[t.b];
165 }
166}
Eli Friedman999af7b2013-07-09 01:38:07 +0000167
168// <rdar://problem/14354144>
169@interface PropertyOfItself
170@property (readonly, nonatomic) PropertyOfItself x; // expected-error {{interface type cannot be statically allocated}}
171@end
172@implementation PropertyOfItself
173@synthesize x;
174@end