blob: 15aa5811cc53518a0be4dc98c042c5b0acaf94f4 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
Steve Naroffc0febd52008-12-10 17:49:55 +00002@protocol NSObject;
3
4void bar(id(^)(void));
5void foo(id <NSObject>(^objectCreationBlock)(void)) {
6 return bar(objectCreationBlock);
7}
8
9void bar2(id(*)(void));
10void foo2(id <NSObject>(*objectCreationBlock)(void)) {
11 return bar2(objectCreationBlock);
12}
13
14void bar3(id(*)());
15void foo3(id (*objectCreationBlock)(int)) {
16 return bar3(objectCreationBlock);
17}
18
19void bar4(id(^)());
20void foo4(id (^objectCreationBlock)(int)) {
Mike Stumpaab0f7a2009-04-01 01:17:39 +000021 return bar4(objectCreationBlock);
Steve Naroffc0febd52008-12-10 17:49:55 +000022}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000023
Douglas Gregora41a8c52010-04-22 00:20:18 +000024void bar5(id(^)(void)); // expected-note{{passing argument to parameter here}}
Mike Stumpaab0f7a2009-04-01 01:17:39 +000025void foo5(id (^objectCreationBlock)(int)) {
Douglas Gregord4eea832010-04-09 00:35:39 +000026 return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(int)' to parameter of type 'id (^)(void)'}}
Mike Stumpaab0f7a2009-04-01 01:17:39 +000027}
28
29void bar6(id(^)(int));
30void foo6(id (^objectCreationBlock)()) {
Eli Friedman687abff2009-06-08 04:24:21 +000031 return bar6(objectCreationBlock);
Mike Stumpaab0f7a2009-04-01 01:17:39 +000032}
33
Chris Lattnerbb749822009-04-11 19:17:25 +000034void foo7(id (^x)(int)) {
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000035 if (x) { }
36}
Chris Lattnerbb749822009-04-11 19:17:25 +000037
38@interface itf
39@end
40
41void foo8() {
Fariborz Jahaniane9f55812010-04-07 00:22:00 +000042 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 Lattnerbb749822009-04-11 19:17:25 +000046}
Fariborz Jahaniana5e42a82009-08-14 21:53:27 +000047
48
49int foo9() {
50 typedef void (^DVTOperationGroupScheduler)();
51 id _suboperationSchedulers;
52
53 for (DVTOperationGroupScheduler scheduler in _suboperationSchedulers) {
54 ;
55 }
56
57}
Fariborz Jahanian2263f822010-03-09 18:34:52 +000058
59// rdar 7725203
60@class NSString;
61
62extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
63
64void foo10() {
65 void(^myBlock)(void) = ^{
66 };
67 NSLog(@"%@", myBlock);
68}
69