From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaObjCXX/instantiate-expr.mm | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 clang/test/SemaObjCXX/instantiate-expr.mm (limited to 'clang/test/SemaObjCXX/instantiate-expr.mm') diff --git a/clang/test/SemaObjCXX/instantiate-expr.mm b/clang/test/SemaObjCXX/instantiate-expr.mm new file mode 100644 index 0000000..75a5b7e --- /dev/null +++ b/clang/test/SemaObjCXX/instantiate-expr.mm @@ -0,0 +1,75 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface A { +@public + int ivar; +} +@property int prop; +@end + +typedef struct objc_object { + Class isa; +} *id; + +// Test instantiation of value-dependent ObjCIvarRefExpr, +// ObjCIsaRefExpr, and ObjCPropertyRefExpr nodes. +A *get_an_A(unsigned); +id get_an_id(unsigned); + +template +void f(U value, V value2) { + get_an_A(N)->ivar = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}} + get_an_A(N).prop = value2; // expected-error{{assigning to 'int' from incompatible type 'double *'}} + T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \ + // expected-warning 5 {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} +} + +template void f<6, Class>(int, int); // expected-note{{in instantiation of}} +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}} + +// Test instantiation of unresolved member reference expressions to an +// ivar reference. +template +void f2(T ptr, U value, V value2) { + ptr->ivar = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}} + ptr.prop = value2; // expected-error{{assigning to 'int' from incompatible type 'double *'}} +} + +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}} + +// Test instantiation of unresolved member referfence expressions to +// an isa. +template +void f3(U ptr) { + T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \ + // expected-warning 2 {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} +} + +template void f3(id); // expected-note{{in instantiation of}} +template void f3(id); // expected-note{{instantiation of}} + +// Implicit setter/getter +@interface B +- (int)foo; +- (void)setFoo:(int)value; +@end + +template +void f4(B *b, T value) { + b.foo = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}} +} + +template void f4(B*, int); +template void f4(B*, int*); // expected-note{{in instantiation of function template specialization 'f4' requested here}} + +template +void f5(T ptr, U value) { + ptr.foo = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}} +} + +template void f5(B*, int); +template void f5(B*, int*); // expected-note{{in instantiation of function template specialization 'f5' requested here}} -- cgit v1.2.3