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