blob: 2110f2ce4529ede8296d1c5a9df73115a35d5ef9 [file] [log] [blame]
Steve Naroffc50a4a52008-09-16 22:25:10 +00001// RUN: clang -fsyntax-only %s -verify
2
3typedef void (^CL)(void);
4
5CL 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
48typedef int (^CL2)(void);
49
50CL2 foo2() {
51 return ^{ return 1; }; // expected-error {{returning block that lives on the local stack}}
52}
Steve Naroff16564422008-09-24 22:26:48 +000053
54typedef unsigned int * uintptr_t;
55typedef char Boolean;
56typedef int CFBasicHash;
57
58#define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
59
60typedef struct {
61 Boolean (^isEqual)(const CFBasicHash *, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key);
62} CFBasicHashCallbacks;
63
64int 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}