diff options
author | Mike Stump <mrs@apple.com> | 2009-02-04 22:31:32 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-02-04 22:31:32 +0000 |
commit | 98eb8a7a702b95183ed015706b1f1c66f5cb27a4 (patch) | |
tree | c8447654c9c0f9e1bb7655e0d01a6edf33fc347c /test | |
parent | 90350b6f815eecd9441119b1412695d33fb2b98f (diff) |
Add support for blocks with explicit return types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63784 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/Sema/block-explicit-return-type.c | 81 | ||||
-rw-r--r-- | test/Sema/block-return.c | 29 | ||||
-rw-r--r-- | test/Sema/block-syntax-error.c | 4 |
3 files changed, 96 insertions, 18 deletions
diff --git a/test/Sema/block-explicit-return-type.c b/test/Sema/block-explicit-return-type.c new file mode 100644 index 0000000000..a0d5da6ee8 --- /dev/null +++ b/test/Sema/block-explicit-return-type.c @@ -0,0 +1,81 @@ +// RUN: clang -ObjC -fsyntax-only %s -verify -fblocks +// FIXME: should compile +// Test for blocks with explicit return type specified. + +typedef float * PF; +float gf; + +@interface NSView + - (id) some_method_that_returns_id; +@end + +NSView *some_object; + +void some_func (NSView * (^) (id)); + +typedef struct dispatch_item_s *dispatch_item_t; +typedef void (^completion_block_t)(void); + +typedef double (^myblock)(int); +double test(myblock I); + +int main() +{ + __block int x = 1; + __block int y = 2; + + (void)^void *{ return 0; }; + + (void)^float(float y){ return y; }; + + (void)^double (float y, double d) + { + if (y) + return d; + else + return y; + }; + + const char * (^chb) (int flag, const char *arg, char *arg1) = ^ const char * (int flag, const char *arg, char *arg1) { + if (flag) + return 0; + if (flag == 1) + return arg; + else if (flag == 2) + return ""; + return arg1; + }; + + (void)^PF { return &gf; }; + + some_func(^ NSView * (id whatever) { return [some_object some_method_that_returns_id]; }); + + double res = test(^(int z){x = y+z; return (double)z; }); +} + +void func() +{ + completion_block_t X; + + completion_block_t (^blockx)(dispatch_item_t) = ^completion_block_t (dispatch_item_t item) { + return X; + }; + + completion_block_t (^blocky)(dispatch_item_t) = ^(dispatch_item_t item) { + return X; + }; + + blockx = blocky; + +} + + +// intent: block taking int returning block that takes char,int and returns int +int (^(^block)(double x))(char, short); + +void foo() { + int one = 1; + block = ^(double x){ return ^(char c, short y) { return one + c + y; };}; // expected-error {{returning block that lives on the local stack}} + // or: + block = ^(double x){ return ^(char c, short y) { return one + (int)c + y; };}; // expected-error {{returning block that lives on the local stack}} +} diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index e835c96317..64c29935f5 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -3,24 +3,23 @@ typedef void (^CL)(void); CL foo() { - - short y; - + short y; short (^add1)(void) = ^{ return y+1; }; // expected-warning {{incompatible block pointer types initializing 'int (^)(void)', expected 'short (^)(void)'}} - CL X = ^{ - if (2) - return; + CL X = ^{ + if (2) + return; return 1; // expected-error {{void block should not return a value}} }; - int (^Y) (void) = ^{ + + int (^Y) (void) = ^{ if (3) return 1; else return; // expected-error {{non-void block should return a value}} }; - char *(^Z)(void) = ^{ + char *(^Z)(void) = ^{ if (3) return ""; else @@ -28,20 +27,20 @@ CL foo() { }; double (^A)(void) = ^ { // expected-warning {{incompatible block pointer types initializing 'float (^)(void)', expected 'double (^)(void)'}} - if (1) - return (float)1.0; + if (1) + return (float)1.0; else if (2) - return (double)2.0; // expected-error {{incompatible type returning 'double', expected 'float'}} - return 1; // expected-error {{incompatible type returning 'int', expected 'float'}} + return (double)2.0; + return 1; }; - - char *(^B)(void) = ^{ + char *(^B)(void) = ^{ if (3) return ""; else - return 2; // expected-error {{incompatible type returning 'int', expected 'char *'}} + return 2; // expected-warning {{incompatible integer to pointer conversion returning 'int', expected 'char *'}} }; + return ^{ return 1; }; // expected-warning {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}} expected-error {{returning block that lives on the local stack}} } diff --git a/test/Sema/block-syntax-error.c b/test/Sema/block-syntax-error.c index c98f1fd2aa..5f6c204a47 100644 --- a/test/Sema/block-syntax-error.c +++ b/test/Sema/block-syntax-error.c @@ -3,7 +3,5 @@ void (^noop)(void); void somefunction() { - noop = ^int *{}; // expected-error {{expected expression}} - - noop = ^noop; // expected-error {{expected expression}} + noop = ^noop; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}} } |