blob: 187f7d8274d1862f01987e054a15d1c87ae005f4 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
Douglas Gregor30c42402011-09-27 22:38:19 +00002
3#define bool _Bool
Steve Naroffc0febd52008-12-10 17:49:55 +00004@protocol NSObject;
5
6void bar(id(^)(void));
7void foo(id <NSObject>(^objectCreationBlock)(void)) {
8 return bar(objectCreationBlock);
9}
10
11void bar2(id(*)(void));
12void foo2(id <NSObject>(*objectCreationBlock)(void)) {
13 return bar2(objectCreationBlock);
14}
15
16void bar3(id(*)());
17void foo3(id (*objectCreationBlock)(int)) {
18 return bar3(objectCreationBlock);
19}
20
21void bar4(id(^)());
22void foo4(id (^objectCreationBlock)(int)) {
Mike Stumpaab0f7a2009-04-01 01:17:39 +000023 return bar4(objectCreationBlock);
Steve Naroffc0febd52008-12-10 17:49:55 +000024}
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000025
Douglas Gregora41a8c52010-04-22 00:20:18 +000026void bar5(id(^)(void)); // expected-note{{passing argument to parameter here}}
Douglas Gregor30c42402011-09-27 22:38:19 +000027void foo5(id (^objectCreationBlock)(bool)) {
28 return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(bool)' to parameter of type 'id (^)(void)'}}
Mike Stumpaab0f7a2009-04-01 01:17:39 +000029}
30
31void bar6(id(^)(int));
32void foo6(id (^objectCreationBlock)()) {
Eli Friedman687abff2009-06-08 04:24:21 +000033 return bar6(objectCreationBlock);
Mike Stumpaab0f7a2009-04-01 01:17:39 +000034}
35
Chris Lattnerbb749822009-04-11 19:17:25 +000036void foo7(id (^x)(int)) {
Douglas Gregor2a7e58d2008-12-23 00:53:59 +000037 if (x) { }
38}
Chris Lattnerbb749822009-04-11 19:17:25 +000039
40@interface itf
41@end
42
43void foo8() {
Fariborz Jahaniane9f55812010-04-07 00:22:00 +000044 void *P = ^(itf x) {}; // expected-error {{Objective-C interface type 'itf' cannot be passed by value; did you forget * in 'itf'}}
45 P = ^itf(int x) {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}}
46 P = ^itf() {}; // expected-error {{Objective-C interface type 'itf' cannot be returned by value; did you forget * in 'itf'}}
47 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 +000048}
Fariborz Jahaniana5e42a82009-08-14 21:53:27 +000049
50
51int foo9() {
52 typedef void (^DVTOperationGroupScheduler)();
53 id _suboperationSchedulers;
54
55 for (DVTOperationGroupScheduler scheduler in _suboperationSchedulers) {
56 ;
57 }
58
59}
Fariborz Jahanian2263f822010-03-09 18:34:52 +000060
61// rdar 7725203
62@class NSString;
63
64extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
65
66void foo10() {
67 void(^myBlock)(void) = ^{
68 };
69 NSLog(@"%@", myBlock);
70}
71