diff options
Diffstat (limited to 'test/SemaObjCXX')
-rw-r--r-- | test/SemaObjCXX/blocks.mm | 46 | ||||
-rw-r--r-- | test/SemaObjCXX/cocoa.mm | 4 | ||||
-rw-r--r-- | test/SemaObjCXX/linkage-spec.mm | 4 | ||||
-rw-r--r-- | test/SemaObjCXX/objc-decls-inside-namespace.mm | 27 | ||||
-rw-r--r-- | test/SemaObjCXX/overload.mm | 94 | ||||
-rw-r--r-- | test/SemaObjCXX/protocol-lookup.mm | 50 | ||||
-rw-r--r-- | test/SemaObjCXX/reserved-keyword-selectors.mm | 35 | ||||
-rw-r--r-- | test/SemaObjCXX/vararg-non-pod.mm | 32 | ||||
-rw-r--r-- | test/SemaObjCXX/void_to_obj.mm | 11 |
9 files changed, 303 insertions, 0 deletions
diff --git a/test/SemaObjCXX/blocks.mm b/test/SemaObjCXX/blocks.mm new file mode 100644 index 0000000..3d421a8 --- /dev/null +++ b/test/SemaObjCXX/blocks.mm @@ -0,0 +1,46 @@ +// RUN: clang-cc -fsyntax-only -verify -fblocks %s +@protocol NSObject; + +void bar(id(^)(void)); +void foo(id <NSObject>(^objectCreationBlock)(void)) { + return bar(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id (^)(void)', expected 'id<NSObject> (^)(void)'}} +} + +void bar2(id(*)(void)); +void foo2(id <NSObject>(*objectCreationBlock)(void)) { + return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id (*)(void)', expected 'id<NSObject> (*)(void)'}} +} + +void bar3(id(*)()); // expected-note{{candidate function}} +void foo3(id (*objectCreationBlock)(int)) { + return bar3(objectCreationBlock); // expected-error{{no matching}} +} + +void bar4(id(^)()); // expected-note{{candidate function}} +void foo4(id (^objectCreationBlock)(int)) { + return bar4(objectCreationBlock); // expected-error{{no matching}} +} + +void foo5(id (^x)(int)) { + if (x) { } +} + +// <rdar://problem/6590445> +@interface Foo { + @private + void (^_block)(void); +} +- (void)bar; +@end + +namespace N { + class X { }; + void foo(X); +} + +@implementation Foo +- (void)bar { + _block(); + foo(N::X()); // okay +} +@end diff --git a/test/SemaObjCXX/cocoa.mm b/test/SemaObjCXX/cocoa.mm new file mode 100644 index 0000000..c061d4e --- /dev/null +++ b/test/SemaObjCXX/cocoa.mm @@ -0,0 +1,4 @@ +// RUN: clang-cc -mcpu=pentium4 %s -print-stats +#ifdef __APPLE__ +#include <Cocoa/Cocoa.h> +#endif diff --git a/test/SemaObjCXX/linkage-spec.mm b/test/SemaObjCXX/linkage-spec.mm new file mode 100644 index 0000000..2cc0936 --- /dev/null +++ b/test/SemaObjCXX/linkage-spec.mm @@ -0,0 +1,4 @@ +// RUN: clang-cc -fsyntax-only -verify %s +extern "C" { +@class Protocol; +} diff --git a/test/SemaObjCXX/objc-decls-inside-namespace.mm b/test/SemaObjCXX/objc-decls-inside-namespace.mm new file mode 100644 index 0000000..cedfcfd --- /dev/null +++ b/test/SemaObjCXX/objc-decls-inside-namespace.mm @@ -0,0 +1,27 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +namespace C { + +@protocol P; //expected-error{{Objective-C declarations may only appear in global scope}} + +@class Bar; //expected-error{{Objective-C declarations may only appear in global scope}} + +@compatibility_alias Foo Bar; //expected-error{{Objective-C declarations may only appear in global scope}} + +@interface A //expected-error{{Objective-C declarations may only appear in global scope}} +@end + +@implementation A //expected-error{{Objective-C declarations may only appear in global scope}} +@end + +@protocol P //expected-error{{Objective-C declarations may only appear in global scope}} +@end + +@interface A(C) //expected-error{{Objective-C declarations may only appear in global scope}} +@end + +@implementation A(C) //expected-error{{Objective-C declarations may only appear in global scope}} +@end + +} + diff --git a/test/SemaObjCXX/overload.mm b/test/SemaObjCXX/overload.mm new file mode 100644 index 0000000..8ab22e1 --- /dev/null +++ b/test/SemaObjCXX/overload.mm @@ -0,0 +1,94 @@ +// RUN: clang-cc -fsyntax-only -verify %s +@interface Foo +@end + +@implementation Foo + +void func(id); + ++ zone { + func(self); + return self; +} +@end + +@protocol P0 +@end + +@protocol P1 +@end + +@interface A <P0> +@end + +@interface B : A +@end + +@interface C <P1> +@end + +int& f(A*); +float& f(B*); +void g(A*); + +int& h(A*); +float& h(id); + +void test(A* a, B* b, id val) { + int& i1 = f(a); + float& f1 = f(b); + float& f2 = f(val); + g(a); + g(b); + g(val); + int& i2 = h(a); + float& f3 = h(val); + // int& i3 = h(b); FIXME: we match GCC here, but shouldn't this work? +} + +void downcast_test(A* a, A** ap) { + B* b = a; // expected-warning{{incompatible pointer types initializing 'B *', expected 'A *'}} + b = a; // expected-warning{{incompatible pointer types assigning 'B *', expected 'A *'}} + + B** bp = ap; // expected-warning{{incompatible pointer types initializing 'B **', expected 'A **'}} + bp = ap; // expected-warning{{incompatible pointer types assigning 'B **', expected 'A **'}} +} + +int& cv(A*); +float& cv(const A*); +int& cv2(void*); +float& cv2(const void*); + +void cv_test(A* a, B* b, const A* ac, const B* bc) { + int &i1 = cv(a); + int &i2 = cv(b); + float &f1 = cv(ac); + float &f2 = cv(bc); + int& i3 = cv2(a); + float& f3 = cv2(ac); +} + + +int& qualid(id<P0>); +float& qualid(id<P1>); // FIXME: GCC complains that this isn't an overload. Is it? + +void qualid_test(A *a, B *b, C *c) { + int& i1 = qualid(a); + int& i2 = qualid(b); + float& f1 = qualid(c); + + id<P0> p1 = 0; + p1 = 0; +} + + +@class NSException; +typedef struct { + void (*throw_exc)(id); +} +objc_exception_functions_t; + +void (*_NSExceptionRaiser(void))(NSException *) { + objc_exception_functions_t exc_funcs; + return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(NSException *)', expected 'void (*)(id)'}} +} diff --git a/test/SemaObjCXX/protocol-lookup.mm b/test/SemaObjCXX/protocol-lookup.mm new file mode 100644 index 0000000..0f1860d --- /dev/null +++ b/test/SemaObjCXX/protocol-lookup.mm @@ -0,0 +1,50 @@ +// RUN: clang-cc -fsyntax-only -verify %s +@protocol NSObject +- retain; +- release; +@end + +@interface NSObject +- init; +- dealloc; +@end + +@protocol Foo <NSObject> +@end + +@protocol Bar <Foo> +@end + +@interface Baz : NSObject { + id <Foo> _foo; + id <Bar> _bar; +} +- (id)initWithFoo:(id <Foo>)foo bar:(id <Bar>)bar; +@end + +@implementation Baz + +- (id)init +{ + return [self initWithFoo:0 bar:0]; +} + +- (id)initWithFoo:(id <Foo>)foo bar:(id <Bar>)bar +{ + self = [super init]; + if (self != 0) { + _foo = [foo retain]; + _bar = [bar retain]; + } + return self; +} + +- dealloc +{ + [_foo release]; + [_bar release]; + [super dealloc]; +} + +@end + diff --git a/test/SemaObjCXX/reserved-keyword-selectors.mm b/test/SemaObjCXX/reserved-keyword-selectors.mm new file mode 100644 index 0000000..2875f935 --- /dev/null +++ b/test/SemaObjCXX/reserved-keyword-selectors.mm @@ -0,0 +1,35 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +@interface A +- (void)asm; +- (void)bool; +- (void)catch; +- (void)class; +- (void)const_cast; +- (void)delete; +- (void)dynamic_cast; +- (void)explicit; +- (void)export; +- (void)false; +- (void)friend; +- (void)mutable; +- (void)namespace; +- (void)new; +- (void)operator; +- (void)private; +- (void)protected; +- (void)public; +- (void)reinterpret_cast; +- (void)static_cast; +- (void)template; +- (void)this; +- (void)throw; +- (void)true; +- (void)try; +- (void)typename; +- (void)typeid; +- (void)using; +- (void)virtual; +- (void)wchar_t; +@end + diff --git a/test/SemaObjCXX/vararg-non-pod.mm b/test/SemaObjCXX/vararg-non-pod.mm new file mode 100644 index 0000000..eeed09e --- /dev/null +++ b/test/SemaObjCXX/vararg-non-pod.mm @@ -0,0 +1,32 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +extern char version[]; + +@protocol P; + +class C { +public: + C(int); +}; + +@interface D +- (void)g:(int)a, ...; +@end + +void t1(D *d) +{ + C c(10); + + [d g:10, c]; // expected-warning{{cannot pass object of non-POD type 'class C' through variadic method; call will abort at runtime}} + [d g:10, version]; +} + +void t2(D *d, id p) +{ + [d g:10, p]; +} + +void t3(D *d, id<P> p) +{ + [d g:10, p]; +} diff --git a/test/SemaObjCXX/void_to_obj.mm b/test/SemaObjCXX/void_to_obj.mm new file mode 100644 index 0000000..d1fbf6b --- /dev/null +++ b/test/SemaObjCXX/void_to_obj.mm @@ -0,0 +1,11 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +// <rdar://problem/6463729> +@class XX; + +void func() { + XX *obj; + void *vv; + + obj = vv; // expected-error{{incompatible type assigning 'void *', expected 'XX *'}} +} |