diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-05-04 16:12:48 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-05-04 16:12:48 +0000 |
commit | 8aaf5818a64e9f7687798852af5945b053c68a54 (patch) | |
tree | d6a70c3518b8dea8be7062438d7e8676820ed17f /test/SemaObjCXX | |
parent | 71438373cd57f0d5d8c93bb5cf690844a0fbc9d0 (diff) | |
download | FreeBSD-src-8aaf5818a64e9f7687798852af5945b053c68a54.zip FreeBSD-src-8aaf5818a64e9f7687798852af5945b053c68a54.tar.gz |
Update clang to r103004.
Diffstat (limited to 'test/SemaObjCXX')
-rw-r--r-- | test/SemaObjCXX/blocks.mm | 4 | ||||
-rw-r--r-- | test/SemaObjCXX/instantiate-expr.mm | 73 | ||||
-rw-r--r-- | test/SemaObjCXX/instantiate-message.mm | 50 | ||||
-rw-r--r-- | test/SemaObjCXX/instantiate-stmt.mm | 77 | ||||
-rw-r--r-- | test/SemaObjCXX/ivar-lookup.mm | 18 | ||||
-rw-r--r-- | test/SemaObjCXX/ivar-reference-type.mm | 5 | ||||
-rw-r--r-- | test/SemaObjCXX/linkage-spec.mm | 8 | ||||
-rw-r--r-- | test/SemaObjCXX/message.mm | 77 | ||||
-rw-r--r-- | test/SemaObjCXX/objc-pointer-conv.mm | 4 | ||||
-rw-r--r-- | test/SemaObjCXX/overload-1.mm | 25 | ||||
-rw-r--r-- | test/SemaObjCXX/parameters.mm | 12 | ||||
-rw-r--r-- | test/SemaObjCXX/void_to_obj.mm | 2 |
12 files changed, 344 insertions, 11 deletions
diff --git a/test/SemaObjCXX/blocks.mm b/test/SemaObjCXX/blocks.mm index 72de171..fd0df4e 100644 --- a/test/SemaObjCXX/blocks.mm +++ b/test/SemaObjCXX/blocks.mm @@ -3,12 +3,12 @@ void bar(id(^)(void)); void foo(id <NSObject>(^objectCreationBlock)(void)) { - return bar(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id (^)()', expected 'id<NSObject> (^)()'}} + return bar(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id<NSObject> (^)()' to type 'id (^)()'}} } void bar2(id(*)(void)); void foo2(id <NSObject>(*objectCreationBlock)(void)) { - return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id (*)()', expected 'id<NSObject> (*)()'}} + return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id<NSObject> (*)()' to type 'id (*)()'}} } void bar3(id(*)()); // expected-note{{candidate function}} diff --git a/test/SemaObjCXX/instantiate-expr.mm b/test/SemaObjCXX/instantiate-expr.mm new file mode 100644 index 0000000..08be5f7 --- /dev/null +++ b/test/SemaObjCXX/instantiate-expr.mm @@ -0,0 +1,73 @@ +// 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<unsigned N, typename T, typename U, typename V> +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'}} +} + +template void f<6, Class>(int, int); +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<typename T, typename U, typename V> +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<typename T, typename U> +void f3(U ptr) { + T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} +} + +template void f3<Class>(id); +template void f3<int>(id); // expected-note{{instantiation of}} + +// Implicit setter/getter +@interface B +- (int)foo; +- (void)setFoo:(int)value; +@end + +template<typename T> +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<int *>' requested here}} + +template<typename T, typename U> +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<B *, int *>' requested here}} diff --git a/test/SemaObjCXX/instantiate-message.mm b/test/SemaObjCXX/instantiate-message.mm new file mode 100644 index 0000000..46c8ede --- /dev/null +++ b/test/SemaObjCXX/instantiate-message.mm @@ -0,0 +1,50 @@ +// RUN: %clang -cc1 -fsyntax-only -verify %s + +// Test template instantiation of Objective-C message sends. + +@interface ClassMethods ++ (ClassMethods *)method1:(void*)ptr; +@end + +template<typename T> +struct identity { + typedef T type; +}; + +template<typename R, typename T, typename Arg1> +void test_class_method(Arg1 arg1) { + R *result1 = [T method1:arg1]; + R *result2 = [typename identity<T>::type method1:arg1]; + R *result3 = [ClassMethods method1:arg1]; // expected-error{{cannot initialize a variable of type 'ClassMethods2 *' with an rvalue of type 'ClassMethods *'}} +} + +template void test_class_method<ClassMethods, ClassMethods>(void*); +template void test_class_method<ClassMethods, ClassMethods>(int*); + +@interface ClassMethods2 ++ (ClassMethods2 *)method1:(int*)ptr; +@end + +template void test_class_method<ClassMethods2, ClassMethods2>(int*); // expected-note{{in instantiation of}} + + +@interface InstanceMethods +- (InstanceMethods *)method1:(void*)ptr; +@end + +template<typename R, typename T, typename Arg1> +void test_instance_method(Arg1 arg1) { + T *receiver = 0; + InstanceMethods *im = 0; + R *result1 = [receiver method1:arg1]; + R *result2 = [im method1:arg1]; // expected-error{{cannot initialize a variable of type 'InstanceMethods2 *' with an rvalue of type 'InstanceMethods *'}} +} + +template void test_instance_method<InstanceMethods, InstanceMethods>(void*); +template void test_instance_method<InstanceMethods, InstanceMethods>(int*); + +@interface InstanceMethods2 +- (InstanceMethods2 *)method1:(void*)ptr; +@end + +template void test_instance_method<InstanceMethods2, InstanceMethods2>(int*); // expected-note{{in instantiation of}} diff --git a/test/SemaObjCXX/instantiate-stmt.mm b/test/SemaObjCXX/instantiate-stmt.mm new file mode 100644 index 0000000..e92f8e8 --- /dev/null +++ b/test/SemaObjCXX/instantiate-stmt.mm @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface NSException +@end + +// @throw +template<typename T> +void throw_test(T value) { + @throw value; // expected-error{{@throw requires an Objective-C object type ('int' invalid)}} +} + +template void throw_test(NSException *); +template void throw_test(int); // expected-note{{in instantiation of}} + +// @synchronized +template<typename T> +void synchronized_test(T value) { + @synchronized (value) { // expected-error{{@synchronized requires an Objective-C object type ('int' invalid)}} + value = 0; + } +} + +template void synchronized_test(NSException *); +template void synchronized_test(int); // expected-note{{in instantiation of}} + +// fast enumeration +@interface NSArray +@end + +@interface NSString +@end + +struct vector {}; + +template<typename T> void eat(T); + +template<typename E, typename T> +void fast_enumeration_test(T collection) { + for (E element in collection) { // expected-error{{selector element type 'int' is not a valid object}} \ + // expected-error{{collection expression type 'vector' is not a valid object}} + eat(element); + } + + E element; + for (element in collection) // expected-error{{selector element type 'int' is not a valid object}} \ + // expected-error{{collection expression type 'vector' is not a valid object}} + eat(element); + + for (NSString *str in collection) // expected-error{{collection expression type 'vector' is not a valid object}} + eat(str); + + NSString *str; + for (str in collection) // expected-error{{collection expression type 'vector' is not a valid object}} + eat(str); +} + +template void fast_enumeration_test<NSString *>(NSArray*); +template void fast_enumeration_test<int>(NSArray*); // expected-note{{in instantiation of}} +template void fast_enumeration_test<NSString *>(vector); // expected-note{{in instantiation of}} + +// @try/@catch/@finally + +template<typename T, typename U> +void try_catch_finally_test(U value) { + @try { + value = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}} + } + @catch (T obj) { // expected-error{{@catch parameter is not a pointer to an interface type}} + id x = obj; + } @finally { + value = 0; + } +} + +template void try_catch_finally_test<NSString *>(int); +template void try_catch_finally_test<NSString *>(int*); // expected-note{{in instantiation of}} +template void try_catch_finally_test<NSString>(int); // expected-note{{in instantiation of function template specialization 'try_catch_finally_test<NSString, int>' requested here}} diff --git a/test/SemaObjCXX/ivar-lookup.mm b/test/SemaObjCXX/ivar-lookup.mm new file mode 100644 index 0000000..bb26f48 --- /dev/null +++ b/test/SemaObjCXX/ivar-lookup.mm @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +@interface Ivar +- (float*)method; +@end + +@interface A { + A *Ivar; +} +- (int*)method; +@end + +@implementation A +- (int*)method { + int *ip = [Ivar method]; // Okay; calls A's method on the instance variable Ivar. + // Note that Objective-C calls Ivar's method. + return 0; +} +@end diff --git a/test/SemaObjCXX/ivar-reference-type.mm b/test/SemaObjCXX/ivar-reference-type.mm new file mode 100644 index 0000000..2b5df45 --- /dev/null +++ b/test/SemaObjCXX/ivar-reference-type.mm @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +@interface A { + int &r; // expected-error {{instance variables cannot be of reference type}} +} +@end diff --git a/test/SemaObjCXX/linkage-spec.mm b/test/SemaObjCXX/linkage-spec.mm index b4e809e..1454e6a 100644 --- a/test/SemaObjCXX/linkage-spec.mm +++ b/test/SemaObjCXX/linkage-spec.mm @@ -2,3 +2,11 @@ extern "C" { @class Protocol; } + +// <rdar://problem/7827709> +extern "C" { +@class I; +} + +@interface I +@end diff --git a/test/SemaObjCXX/message.mm b/test/SemaObjCXX/message.mm index 93a600a..b75608e 100644 --- a/test/SemaObjCXX/message.mm +++ b/test/SemaObjCXX/message.mm @@ -1,12 +1,13 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s @interface I1 -- (void)method; +- (int*)method; @end @implementation I1 -- (void)method { +- (int*)method { struct x { }; - [x method]; // expected-error{{invalid receiver to message expression}} + [x method]; // expected-error{{receiver type 'x' is not an Objective-C class}} + return 0; } @end @@ -15,15 +16,79 @@ typedef struct { int x; } ivar; @interface I2 { id ivar; } -- (void)method; +- (int*)method; + (void)method; @end +struct I2_holder { + I2_holder(); + + I2 *get(); +}; + +I2 *operator+(I2_holder, int); + @implementation I2 -- (void)method { +- (int*)method { [ivar method]; + + // Test instance messages that start with a simple-type-specifier. + [I2_holder().get() method]; + [I2_holder().get() + 17 method]; + return 0; } + (void)method { - [ivar method]; // expected-error{{invalid receiver to message expression}} + [ivar method]; // expected-error{{receiver type 'ivar' (aka 'ivar') is not an Objective-C class}} +} +@end + +// Class message sends +@interface I3 ++ (int*)method; +@end + +@interface I4 : I3 ++ (int*)otherMethod; +@end + +template<typename T> +struct identity { + typedef T type; +}; + +@implementation I4 ++ (int *)otherMethod { + // Test class messages that use non-trivial simple-type-specifiers + // or typename-specifiers. + if (false) { + if (true) + return [typename identity<I3>::type method]; + + return [::I3 method]; + } + + int* ip1 = {[super method]}; + int* ip2 = {[::I3 method]}; + int* ip3 = {[typename identity<I3>::type method]}; + int* ip4 = {[typename identity<I2_holder>::type().get() method]}; + int array[5] = {[3] = 2}; + return [super method]; } @end + +struct String { + String(const char *); +}; + +struct MutableString : public String { }; + +// C++-specific parameter types +@interface I5 +- method:(const String&)str1 + other:(String&)str2; // expected-note{{passing argument to parameter 'str2' here}} +@end + +void test_I5(I5 *i5, String s) { + [i5 method:"hello" other:s]; + [i5 method:s other:"world"]; // expected-error{{non-const lvalue reference to type 'String' cannot bind to a value of unrelated type 'char const [6]'}} +} diff --git a/test/SemaObjCXX/objc-pointer-conv.mm b/test/SemaObjCXX/objc-pointer-conv.mm index 144bda4..cc3264f 100644 --- a/test/SemaObjCXX/objc-pointer-conv.mm +++ b/test/SemaObjCXX/objc-pointer-conv.mm @@ -26,13 +26,13 @@ void RandomFunc(CFMDRef theDict, const void *key, const void *value); @end @interface I -- (void) Meth : (I*) Arg; +- (void) Meth : (I*) Arg; // expected-note{{passing argument to parameter 'Arg' here}} @end void Func (I* arg); // expected-note {{candidate function not viable: no known conversion from 'I const *' to 'I *' for 1st argument}} void foo(const I *p, I* sel) { - [sel Meth : p]; // expected-error {{incompatible type sending 'I const *', expected 'I *'}} + [sel Meth : p]; // expected-error {{cannot initialize a parameter of type 'I *' with an lvalue of type 'I const *'}} Func(p); // expected-error {{no matching function for call to 'Func'}} } diff --git a/test/SemaObjCXX/overload-1.mm b/test/SemaObjCXX/overload-1.mm new file mode 100644 index 0000000..fc17ca2 --- /dev/null +++ b/test/SemaObjCXX/overload-1.mm @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@protocol Proto1 @end + +@protocol Proto2 @end + +void f(id<Proto1> *) { } // expected-note {{previous definition is here}} + +void f(id<Proto1, Proto2> *) { } // expected-error {{conflicting types for 'f'}} + +void f(Class<Proto1> *) { } // expected-note {{previous definition is here}} + +void f(Class<Proto1, Proto2> *) { } // expected-error {{conflicting types for 'f'}} + +@interface I @end + +void f(I<Proto1> *) { } // expected-note {{previous definition is here}} + +void f(I<Proto1, Proto2> *) { } // expected-error {{conflicting types for 'f'}} + +@interface I1 @end + +void f1(I<Proto1> *) { } + +void f1(I1<Proto1, Proto2> *) { } diff --git a/test/SemaObjCXX/parameters.mm b/test/SemaObjCXX/parameters.mm new file mode 100644 index 0000000..aab1fbd --- /dev/null +++ b/test/SemaObjCXX/parameters.mm @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -verify %s + +@interface A +@end + +template<typename T> +struct X0 { + void f(T); // expected-error{{interface type 'A' cannot be passed by value}} +}; + +X0<A> x0a; // expected-note{{instantiation}} + diff --git a/test/SemaObjCXX/void_to_obj.mm b/test/SemaObjCXX/void_to_obj.mm index 932827e..52510c8 100644 --- a/test/SemaObjCXX/void_to_obj.mm +++ b/test/SemaObjCXX/void_to_obj.mm @@ -7,5 +7,5 @@ void func() { XX *obj; void *vv; - obj = vv; // expected-error{{incompatible type assigning 'void *', expected 'XX *'}} + obj = vv; // expected-error{{assigning to 'XX *' from incompatible type 'void *'}} } |