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 | } |
Steve Naroff | 1656442 | 2008-09-24 22:26:48 +0000 | [diff] [blame^] | 53 | |
| 54 | typedef unsigned int * uintptr_t; |
| 55 | typedef char Boolean; |
| 56 | typedef int CFBasicHash; |
| 57 | |
| 58 | #define INVOKE_CALLBACK2(P, A, B) (P)(A, B) |
| 59 | |
| 60 | typedef struct { |
| 61 | Boolean (^isEqual)(const CFBasicHash *, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key); |
| 62 | } CFBasicHashCallbacks; |
| 63 | |
| 64 | int foo3() { |
| 65 | CFBasicHashCallbacks cb; |
| 66 | |
| 67 | Boolean (*value_equal)(uintptr_t, uintptr_t) = 0; |
| 68 | |
| 69 | cb.isEqual = ^(const CFBasicHash *table, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key) { |
| 70 | return (Boolean)(uintptr_t)INVOKE_CALLBACK2(value_equal, (uintptr_t)stack_value_or_key1, (uintptr_t)stack_value_or_key2); |
| 71 | }; |
| 72 | } |