blob: ddac7d1759ec84ba26ab47bc0fe997b61c807835 [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
Mike Stumpaab0f7a2009-04-01 01:17:39 +000024void bar5(id(^)(void));
25void foo5(id (^objectCreationBlock)(int)) {
Mike Stump25efa102009-04-21 22:51:42 +000026 return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(int)', expected '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() {
Chris Lattner30bdc872009-04-11 19:18:22 +000042 void *P = ^(itf x) {}; // expected-error {{Objective-C interface type 'itf' cannot be passed by value}}
Chris Lattner9097af12009-04-11 19:27:54 +000043 P = ^itf(int x) {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value}}
44 P = ^itf() {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value}}
45 P = ^itf{}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value}}
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