blob: fd0df4e6e225e8775c09522e106716a668a4a763 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
Douglas Gregor2a7e58d2008-12-23 00:53:59 +00002@protocol NSObject;
3
4void bar(id(^)(void));
5void foo(id <NSObject>(^objectCreationBlock)(void)) {
Douglas Gregord4eea832010-04-09 00:35:39 +00006 return bar(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id<NSObject> (^)()' to type 'id (^)()'}}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +00007}
8
9void bar2(id(*)(void));
10void foo2(id <NSObject>(*objectCreationBlock)(void)) {
Douglas Gregord4eea832010-04-09 00:35:39 +000011 return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id<NSObject> (*)()' to type 'id (*)()'}}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000012}
13
Douglas Gregorfa047642009-02-04 00:32:51 +000014void bar3(id(*)()); // expected-note{{candidate function}}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000015void foo3(id (*objectCreationBlock)(int)) {
Douglas Gregorfa047642009-02-04 00:32:51 +000016 return bar3(objectCreationBlock); // expected-error{{no matching}}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000017}
18
Douglas Gregorfa047642009-02-04 00:32:51 +000019void bar4(id(^)()); // expected-note{{candidate function}}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000020void foo4(id (^objectCreationBlock)(int)) {
Douglas Gregorfa047642009-02-04 00:32:51 +000021 return bar4(objectCreationBlock); // expected-error{{no matching}}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000022}
23
24void foo5(id (^x)(int)) {
25 if (x) { }
26}
Douglas Gregorc71e28c2009-02-16 19:28:42 +000027
28// <rdar://problem/6590445>
29@interface Foo {
30 @private
31 void (^_block)(void);
32}
33- (void)bar;
34@end
35
36namespace N {
37 class X { };
38 void foo(X);
39}
40
41@implementation Foo
42- (void)bar {
43 _block();
44 foo(N::X()); // okay
45}
46@end
Fariborz Jahanian3b27f1a2009-12-11 22:40:48 +000047
48typedef signed char BOOL;
49void foo6(void *block) {
50 void (^vb)(id obj, int idx, BOOL *stop) = (void (^)(id, int, BOOL *))block;
51 BOOL (^bb)(id obj, int idx, BOOL *stop) = (BOOL (^)(id, int, BOOL *))block;
52}