blob: 6dab289ae9f223322dd46b0094c6fc26ce04eca2 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -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}