Fix the clang-wpa example.
[clang.git] / test / SemaObjC / blocks.m
blob15aa5811cc53518a0be4dc98c042c5b0acaf94f4
1 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
2 @protocol NSObject;
4 void bar(id(^)(void));
5 void foo(id <NSObject>(^objectCreationBlock)(void)) {
6     return bar(objectCreationBlock);
9 void bar2(id(*)(void));
10 void foo2(id <NSObject>(*objectCreationBlock)(void)) {
11     return bar2(objectCreationBlock);
14 void bar3(id(*)());
15 void foo3(id (*objectCreationBlock)(int)) {
16     return bar3(objectCreationBlock);
19 void bar4(id(^)());
20 void foo4(id (^objectCreationBlock)(int)) {
21     return bar4(objectCreationBlock);
24 void bar5(id(^)(void)); // expected-note{{passing argument to parameter here}}
25 void foo5(id (^objectCreationBlock)(int)) {
26     return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(int)' to parameter of type 'id (^)(void)'}}
29 void bar6(id(^)(int));
30 void foo6(id (^objectCreationBlock)()) {
31     return bar6(objectCreationBlock);
34 void foo7(id (^x)(int)) {
35   if (x) { }
38 @interface itf
39 @end
41 void foo8() {
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'}}
49 int foo9() {
50   typedef void (^DVTOperationGroupScheduler)();
51   id _suboperationSchedulers;
53   for (DVTOperationGroupScheduler scheduler in _suboperationSchedulers) {
54             ;
55         }
59 // rdar 7725203
60 @class NSString;
62 extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
64 void foo10() {
65     void(^myBlock)(void) = ^{
66     };
67     NSLog(@"%@", myBlock);