Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify -fblocks %s |
Douglas Gregor | 2a7e58d | 2008-12-23 00:53:59 +0000 | [diff] [blame] | 2 | @protocol NSObject; |
| 3 | |
| 4 | void bar(id(^)(void)); |
| 5 | void foo(id <NSObject>(^objectCreationBlock)(void)) { |
| 6 | return bar(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id (^)(void)', expected 'id<NSObject> (^)(void)'}} |
| 7 | } |
| 8 | |
| 9 | void bar2(id(*)(void)); |
| 10 | void foo2(id <NSObject>(*objectCreationBlock)(void)) { |
| 11 | return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id (*)(void)', expected 'id<NSObject> (*)(void)'}} |
| 12 | } |
| 13 | |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 14 | void bar3(id(*)()); // expected-note{{candidate function}} |
Douglas Gregor | 2a7e58d | 2008-12-23 00:53:59 +0000 | [diff] [blame] | 15 | void foo3(id (*objectCreationBlock)(int)) { |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 16 | return bar3(objectCreationBlock); // expected-error{{no matching}} |
Douglas Gregor | 2a7e58d | 2008-12-23 00:53:59 +0000 | [diff] [blame] | 17 | } |
| 18 | |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 19 | void bar4(id(^)()); // expected-note{{candidate function}} |
Douglas Gregor | 2a7e58d | 2008-12-23 00:53:59 +0000 | [diff] [blame] | 20 | void foo4(id (^objectCreationBlock)(int)) { |
Douglas Gregor | fa04764 | 2009-02-04 00:32:51 +0000 | [diff] [blame] | 21 | return bar4(objectCreationBlock); // expected-error{{no matching}} |
Douglas Gregor | 2a7e58d | 2008-12-23 00:53:59 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void foo5(id (^x)(int)) { |
| 25 | if (x) { } |
| 26 | } |
Douglas Gregor | c71e28c | 2009-02-16 19:28:42 +0000 | [diff] [blame] | 27 | |
| 28 | // <rdar://problem/6590445> |
| 29 | @interface Foo { |
| 30 | @private |
| 31 | void (^_block)(void); |
| 32 | } |
| 33 | - (void)bar; |
| 34 | @end |
| 35 | |
| 36 | namespace 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 |