Chris Lattner | ae0ee03 | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s -fblocks |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 2 | |
| 3 | int (*FP)(); |
| 4 | int (^IFP) (); |
| 5 | int (^II) (int); |
| 6 | int 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 Naroff | ba80c9a | 2008-09-24 23:31:10 +0000 | [diff] [blame] | 10 | int (^PFR) (int) = IFP; // expected-warning {{incompatible block pointer types initializing 'int (^)()', expected 'int (^)(int)'}} |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 11 | PFR = II; // OK |
| 12 | |
Steve Naroff | ba80c9a | 2008-09-24 23:31:10 +0000 | [diff] [blame] | 13 | int (^IFP) () = PFR; // expected-warning {{incompatible block pointer types initializing 'int (^)(int)', expected 'int (^)()'}} |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 14 | |
| 15 | |
Steve Naroff | ba80c9a | 2008-09-24 23:31:10 +0000 | [diff] [blame] | 16 | const int (^CIC) () = IFP; // expected-warning {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}} |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | const int (^CICC) () = CIC; |
| 20 | |
| 21 | int * const (^IPCC) () = 0; |
| 22 | |
| 23 | int * const (^IPCC1) () = IPCC; |
| 24 | |
Steve Naroff | ba80c9a | 2008-09-24 23:31:10 +0000 | [diff] [blame] | 25 | int * (^IPCC2) () = IPCC; // expected-warning {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}} |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 26 | |
Steve Naroff | c0febd5 | 2008-12-10 17:49:55 +0000 | [diff] [blame] | 27 | int (^IPCC3) (const int) = PFR; |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 28 | |
| 29 | |
| 30 | int (^IPCC4) (int, char (^CArg) (double)); |
| 31 | |
| 32 | |
| 33 | int (^IPCC5) (int, char (^CArg) (double)) = IPCC4; |
| 34 | |
Steve Naroff | ba80c9a | 2008-09-24 23:31:10 +0000 | [diff] [blame] | 35 | int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-warning {{incompatible block pointer types initializing 'int (^)(int, char (^)(double))', expected 'int (^)(int, char (^)(float))'}} |
Steve Naroff | dd972f2 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 36 | |
| 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 | |
| 45 | int 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 | |