Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s |
Steve Naroff | c0febd5 | 2008-12-10 17:49:55 +0000 | [diff] [blame] | 2 | @protocol NSObject; |
| 3 | |
| 4 | void bar(id(^)(void)); |
| 5 | void foo(id <NSObject>(^objectCreationBlock)(void)) { |
| 6 | return bar(objectCreationBlock); |
| 7 | } |
| 8 | |
| 9 | void bar2(id(*)(void)); |
| 10 | void foo2(id <NSObject>(*objectCreationBlock)(void)) { |
| 11 | return bar2(objectCreationBlock); |
| 12 | } |
| 13 | |
| 14 | void bar3(id(*)()); |
| 15 | void foo3(id (*objectCreationBlock)(int)) { |
| 16 | return bar3(objectCreationBlock); |
| 17 | } |
| 18 | |
| 19 | void bar4(id(^)()); |
| 20 | void foo4(id (^objectCreationBlock)(int)) { |
Mike Stump | aab0f7a | 2009-04-01 01:17:39 +0000 | [diff] [blame] | 21 | return bar4(objectCreationBlock); |
Steve Naroff | c0febd5 | 2008-12-10 17:49:55 +0000 | [diff] [blame] | 22 | } |
Douglas Gregor | 2a7e58d | 2008-12-23 00:53:59 +0000 | [diff] [blame] | 23 | |
Mike Stump | aab0f7a | 2009-04-01 01:17:39 +0000 | [diff] [blame] | 24 | void bar5(id(^)(void)); |
| 25 | void foo5(id (^objectCreationBlock)(int)) { |
Mike Stump | 25efa10 | 2009-04-21 22:51:42 +0000 | [diff] [blame] | 26 | return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(int)', expected 'id (^)(void)'}} |
Mike Stump | aab0f7a | 2009-04-01 01:17:39 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void bar6(id(^)(int)); |
| 30 | void foo6(id (^objectCreationBlock)()) { |
Eli Friedman | 687abff | 2009-06-08 04:24:21 +0000 | [diff] [blame] | 31 | return bar6(objectCreationBlock); |
Mike Stump | aab0f7a | 2009-04-01 01:17:39 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Chris Lattner | bb74982 | 2009-04-11 19:17:25 +0000 | [diff] [blame] | 34 | void foo7(id (^x)(int)) { |
Douglas Gregor | 2a7e58d | 2008-12-23 00:53:59 +0000 | [diff] [blame] | 35 | if (x) { } |
| 36 | } |
Chris Lattner | bb74982 | 2009-04-11 19:17:25 +0000 | [diff] [blame] | 37 | |
| 38 | @interface itf |
| 39 | @end |
| 40 | |
| 41 | void foo8() { |
Fariborz Jahanian | e9f5581 | 2010-04-07 00:22:00 +0000 | [diff] [blame^] | 42 | void *P = ^(itf x) {}; // expected-error {{Objective-C interface type 'itf' cannot be passed by value; did you forget * in 'itf'}} |
| 43 | P = ^itf(int x) {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} |
| 44 | P = ^itf() {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} |
| 45 | P = ^itf{}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}} |
Chris Lattner | bb74982 | 2009-04-11 19:17:25 +0000 | [diff] [blame] | 46 | } |
Fariborz Jahanian | a5e42a8 | 2009-08-14 21:53:27 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | int foo9() { |
| 50 | typedef void (^DVTOperationGroupScheduler)(); |
| 51 | id _suboperationSchedulers; |
| 52 | |
| 53 | for (DVTOperationGroupScheduler scheduler in _suboperationSchedulers) { |
| 54 | ; |
| 55 | } |
| 56 | |
| 57 | } |
Fariborz Jahanian | 2263f82 | 2010-03-09 18:34:52 +0000 | [diff] [blame] | 58 | |
| 59 | // rdar 7725203 |
| 60 | @class NSString; |
| 61 | |
| 62 | extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); |
| 63 | |
| 64 | void foo10() { |
| 65 | void(^myBlock)(void) = ^{ |
| 66 | }; |
| 67 | NSLog(@"%@", myBlock); |
| 68 | } |
| 69 | |