1// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks 2// FIXME: should compile 3// Test for blocks with explicit return type specified. 4 5typedef float * PF; 6float gf; 7 8@interface NSView 9 - (id) some_method_that_returns_id; 10@end 11 12NSView *some_object; 13 14void some_func (NSView * (^) (id)); 15 16typedef struct dispatch_item_s *dispatch_item_t; 17typedef void (^completion_block_t)(void); 18 19typedef double (^myblock)(int); 20double test(myblock I); 21 22int main() { 23 __block int x = 1; 24 __block int y = 2; 25 26 (void)^void *{ return 0; }; 27 28 (void)^float(float y){ return y; }; 29 30 (void)^double (float y, double d) { 31 if (y) 32 return d; 33 else 34 return y; 35 }; 36 37 const char * (^chb) (int flag, const char *arg, char *arg1) = ^ const char * (int flag, const char *arg, char *arg1) { 38 if (flag) 39 return 0; 40 if (flag == 1) 41 return arg; 42 else if (flag == 2) 43 return ""; 44 return arg1; 45 }; 46 47 (void)^PF { return &gf; }; 48 49 some_func(^ NSView * (id whatever) { return [some_object some_method_that_returns_id]; }); 50 51 double res = test(^(int z){x = y+z; return (double)z; }); 52} 53 54void func() { 55 completion_block_t X; 56 57 completion_block_t (^blockx)(dispatch_item_t) = ^completion_block_t (dispatch_item_t item) { 58 return X; 59 }; 60 61 completion_block_t (^blocky)(dispatch_item_t) = ^(dispatch_item_t item) { 62 return X; 63 }; 64 65 blockx = blocky; 66} 67 68 69// intent: block taking int returning block that takes char,int and returns int 70int (^(^block)(double x))(char, short); 71 72void foo() { 73 int one = 1; 74 block = ^(double x){ return ^(char c, short y) { return one + c + y; };}; // expected-error {{returning block that lives on the local stack}} 75 // or: 76 block = ^(double x){ return ^(char c, short y) { return one + (int)c + y; };}; // expected-error {{returning block that lives on the local stack}} 77} 78