blob: c52f0ed96bffa750278653fbae7ea0a665105003 [file] [log] [blame]
Chris Lattnerae0ee032008-12-04 23:20:07 +00001// RUN: clang -fsyntax-only -verify %s -fblocks
Steve Naroffdd972f22008-09-05 22:11:13 +00002
3int (*FP)();
4int (^IFP) ();
5int (^II) (int);
6int main() {
7 int (*FPL) (int) = FP; // C doesn't consider this an error.
8
9 // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
Steve Naroffba80c9a2008-09-24 23:31:10 +000010 int (^PFR) (int) = IFP; // expected-warning {{incompatible block pointer types initializing 'int (^)()', expected 'int (^)(int)'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000011 PFR = II; // OK
12
Steve Naroffba80c9a2008-09-24 23:31:10 +000013 int (^IFP) () = PFR; // expected-warning {{incompatible block pointer types initializing 'int (^)(int)', expected 'int (^)()'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000014
15
Steve Naroffba80c9a2008-09-24 23:31:10 +000016 const int (^CIC) () = IFP; // expected-warning {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000017
18
19 const int (^CICC) () = CIC;
20
21 int * const (^IPCC) () = 0;
22
23 int * const (^IPCC1) () = IPCC;
24
Steve Naroffba80c9a2008-09-24 23:31:10 +000025 int * (^IPCC2) () = IPCC; // expected-warning {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000026
Steve Naroffc0febd52008-12-10 17:49:55 +000027 int (^IPCC3) (const int) = PFR;
Steve Naroffdd972f22008-09-05 22:11:13 +000028
29
30 int (^IPCC4) (int, char (^CArg) (double));
31
32
33 int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
34
Steve Naroffba80c9a2008-09-24 23:31:10 +000035 int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-warning {{incompatible block pointer types initializing 'int (^)(int, char (^)(double))', expected 'int (^)(int, char (^)(float))'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000036
37 IPCC2 = 0;
38 IPCC2 = 1; // expected-error {{invalid conversion assigning integer 'int', expected block pointer 'int *(^)()'}}
39 int (^x)() = 0;
40 int (^y)() = 3; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
41 int a = 1;
42 int (^z)() = a+4; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
43}
44
45int blah() {
46 int (^IFP) (float);
47 char (^PCP)(double, double, char);
48
49 IFP(1.0);
50 IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
51
52 char ch = PCP(1.0, 2.0, 'a');
53 return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
54}
55