blob: e9d296db8feccd95d25a5dd3ea8b861ddbfe4c70 [file] [log] [blame]
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3@interface A {
4@public
5 int ivar;
6}
Douglas Gregore3303542010-04-26 20:47:02 +00007@property int prop;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008@end
9
10typedef struct objc_object {
11 Class isa;
12} *id;
13
Douglas Gregore3303542010-04-26 20:47:02 +000014// Test instantiation of value-dependent ObjCIvarRefExpr,
15// ObjCIsaRefExpr, and ObjCPropertyRefExpr nodes.
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000016A *get_an_A(unsigned);
17id get_an_id(unsigned);
18
Douglas Gregore3303542010-04-26 20:47:02 +000019template<unsigned N, typename T, typename U, typename V>
20void f(U value, V value2) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000021 get_an_A(N)->ivar = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}}
Douglas Gregore3303542010-04-26 20:47:02 +000022 get_an_A(N).prop = value2; // expected-error{{assigning to 'int' from incompatible type 'double *'}}
Fariborz Jahanian556b1d02012-01-18 19:08:56 +000023 T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
Fariborz Jahanian7e352742013-03-27 21:19:25 +000024 // expected-warning 3 {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000025}
26
Fariborz Jahanian556b1d02012-01-18 19:08:56 +000027template void f<6, Class>(int, int); // expected-note{{in instantiation of}}
Douglas Gregore3303542010-04-26 20:47:02 +000028template void f<7, Class>(int*, int); // expected-note{{in instantiation of}}
29template void f<8, Class>(int, double*); // expected-note{{in instantiation of}}
30template void f<9, int>(int, int); // expected-note{{in instantiation of}}
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000031
32// Test instantiation of unresolved member reference expressions to an
33// ivar reference.
Douglas Gregore3303542010-04-26 20:47:02 +000034template<typename T, typename U, typename V>
35void f2(T ptr, U value, V value2) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000036 ptr->ivar = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}}
Douglas Gregore3303542010-04-26 20:47:02 +000037 ptr.prop = value2; // expected-error{{assigning to 'int' from incompatible type 'double *'}}
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000038}
39
Douglas Gregore3303542010-04-26 20:47:02 +000040template void f2(A*, int, int);
41template void f2(A*, int*, int); // expected-note{{instantiation of}}
42template void f2(A*, int, double*); // expected-note{{instantiation of}}
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000043
44// Test instantiation of unresolved member referfence expressions to
45// an isa.
46template<typename T, typename U>
47void f3(U ptr) {
Fariborz Jahanian556b1d02012-01-18 19:08:56 +000048 T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
Fariborz Jahanian7e352742013-03-27 21:19:25 +000049 // expected-warning 1 {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000050}
51
Fariborz Jahanian556b1d02012-01-18 19:08:56 +000052template void f3<Class>(id); // expected-note{{in instantiation of}}
Douglas Gregorf9b9eab2010-04-26 20:11:03 +000053template void f3<int>(id); // expected-note{{instantiation of}}
Douglas Gregor9cbfdd22010-04-26 21:04:54 +000054
55// Implicit setter/getter
56@interface B
57- (int)foo;
58- (void)setFoo:(int)value;
59@end
60
61template<typename T>
62void f4(B *b, T value) {
63 b.foo = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}}
64}
65
66template void f4(B*, int);
67template void f4(B*, int*); // expected-note{{in instantiation of function template specialization 'f4<int *>' requested here}}
68
69template<typename T, typename U>
70void f5(T ptr, U value) {
71 ptr.foo = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}}
72}
73
74template void f5(B*, int);
75template void f5(B*, int*); // expected-note{{in instantiation of function template specialization 'f5<B *, int *>' requested here}}