2010-04-27 04:11:03 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
|
|
|
|
@interface A {
|
|
|
|
@public
|
|
|
|
int ivar;
|
|
|
|
}
|
2010-04-27 04:47:02 +08:00
|
|
|
@property int prop;
|
2010-04-27 04:11:03 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
typedef struct objc_object {
|
|
|
|
Class isa;
|
|
|
|
} *id;
|
|
|
|
|
2010-04-27 04:47:02 +08:00
|
|
|
// Test instantiation of value-dependent ObjCIvarRefExpr,
|
|
|
|
// ObjCIsaRefExpr, and ObjCPropertyRefExpr nodes.
|
2010-04-27 04:11:03 +08:00
|
|
|
A *get_an_A(unsigned);
|
|
|
|
id get_an_id(unsigned);
|
|
|
|
|
2010-04-27 04:47:02 +08:00
|
|
|
template<unsigned N, typename T, typename U, typename V>
|
|
|
|
void f(U value, V value2) {
|
2020-02-25 22:49:59 +08:00
|
|
|
get_an_A(N)->ivar = value; // expected-error{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}}
|
|
|
|
get_an_A(N).prop = value2; // expected-error{{incompatible pointer to integer conversion assigning to 'int' from 'double *'}}
|
2012-01-19 03:08:56 +08:00
|
|
|
T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
|
2013-03-28 05:19:25 +08:00
|
|
|
// expected-warning 3 {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
2010-04-27 04:11:03 +08:00
|
|
|
}
|
|
|
|
|
2012-01-19 03:08:56 +08:00
|
|
|
template void f<6, Class>(int, int); // expected-note{{in instantiation of}}
|
2010-04-27 04:47:02 +08:00
|
|
|
template void f<7, Class>(int*, int); // expected-note{{in instantiation of}}
|
|
|
|
template void f<8, Class>(int, double*); // expected-note{{in instantiation of}}
|
|
|
|
template void f<9, int>(int, int); // expected-note{{in instantiation of}}
|
2010-04-27 04:11:03 +08:00
|
|
|
|
|
|
|
// Test instantiation of unresolved member reference expressions to an
|
|
|
|
// ivar reference.
|
2010-04-27 04:47:02 +08:00
|
|
|
template<typename T, typename U, typename V>
|
|
|
|
void f2(T ptr, U value, V value2) {
|
2020-02-25 22:49:59 +08:00
|
|
|
ptr->ivar = value; // expected-error{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}}
|
|
|
|
ptr.prop = value2; // expected-error{{incompatible pointer to integer conversion assigning to 'int' from 'double *'}}
|
2010-04-27 04:11:03 +08:00
|
|
|
}
|
|
|
|
|
2010-04-27 04:47:02 +08:00
|
|
|
template void f2(A*, int, int);
|
|
|
|
template void f2(A*, int*, int); // expected-note{{instantiation of}}
|
|
|
|
template void f2(A*, int, double*); // expected-note{{instantiation of}}
|
2010-04-27 04:11:03 +08:00
|
|
|
|
|
|
|
// Test instantiation of unresolved member referfence expressions to
|
|
|
|
// an isa.
|
|
|
|
template<typename T, typename U>
|
|
|
|
void f3(U ptr) {
|
2012-01-19 03:08:56 +08:00
|
|
|
T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \
|
2013-03-28 05:19:25 +08:00
|
|
|
// expected-warning 1 {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
|
2010-04-27 04:11:03 +08:00
|
|
|
}
|
|
|
|
|
2012-01-19 03:08:56 +08:00
|
|
|
template void f3<Class>(id); // expected-note{{in instantiation of}}
|
2010-04-27 04:11:03 +08:00
|
|
|
template void f3<int>(id); // expected-note{{instantiation of}}
|
2010-04-27 05:04:54 +08:00
|
|
|
|
|
|
|
// Implicit setter/getter
|
|
|
|
@interface B
|
|
|
|
- (int)foo;
|
|
|
|
- (void)setFoo:(int)value;
|
|
|
|
@end
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void f4(B *b, T value) {
|
2020-02-25 22:49:59 +08:00
|
|
|
b.foo = value; // expected-error{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}}
|
2010-04-27 05:04:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template void f4(B*, int);
|
|
|
|
template void f4(B*, int*); // expected-note{{in instantiation of function template specialization 'f4<int *>' requested here}}
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
|
|
|
void f5(T ptr, U value) {
|
2020-02-25 22:49:59 +08:00
|
|
|
ptr.foo = value; // expected-error{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}}
|
2010-04-27 05:04:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template void f5(B*, int);
|
|
|
|
template void f5(B*, int*); // expected-note{{in instantiation of function template specialization 'f5<B *, int *>' requested here}}
|