Steve Naroff | c50a4a5 | 2008-09-16 22:25:10 +0000 | [diff] [blame^] | 1 | // RUN: clang -fsyntax-only %s -verify |
| 2 | |
| 3 | typedef void (^CL)(void); |
| 4 | |
| 5 | CL foo() { |
| 6 | |
| 7 | short y; |
| 8 | |
| 9 | short (^add1)(void) = ^{ return y+1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(void)', expected 'short (^)(void)'}} |
| 10 | |
| 11 | CL X = ^{ |
| 12 | if (2) |
| 13 | return; |
| 14 | return 1; // expected-error {{void block should not return a value}} |
| 15 | }; |
| 16 | int (^Y) (void) = ^{ |
| 17 | if (3) |
| 18 | return 1; |
| 19 | else |
| 20 | return; // expected-error {{non-void block should return a value}} |
| 21 | }; |
| 22 | |
| 23 | char *(^Z)(void) = ^{ |
| 24 | if (3) |
| 25 | return ""; |
| 26 | else |
| 27 | return (char*)0; |
| 28 | }; |
| 29 | |
| 30 | double (^A)(void) = ^ { // expected-error {{incompatible block pointer types initializing 'float (^)(void)', expected 'double (^)(void)'}} |
| 31 | if (1) |
| 32 | return (float)1.0; |
| 33 | else |
| 34 | if (2) |
| 35 | return (double)2.0; // expected-error {{incompatible type returning 'double', expected 'float'}} |
| 36 | return 1; // expected-error {{incompatible type returning 'int', expected 'float'}} |
| 37 | }; |
| 38 | |
| 39 | char *(^B)(void) = ^{ |
| 40 | if (3) |
| 41 | return ""; |
| 42 | else |
| 43 | return 2; // expected-error {{incompatible type returning 'int', expected 'char *'}} |
| 44 | }; |
| 45 | return ^{ return 1; }; // expected-error {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}} expected-error {{returning block that lives on the local stack}} |
| 46 | } |
| 47 | |
| 48 | typedef int (^CL2)(void); |
| 49 | |
| 50 | CL2 foo2() { |
| 51 | return ^{ return 1; }; // expected-error {{returning block that lives on the local stack}} |
| 52 | } |