1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc int (*FP)();
4*f4a2713aSLionel Sambuc int (^IFP) ();
5*f4a2713aSLionel Sambuc int (^II) (int);
main()6*f4a2713aSLionel Sambuc int main() {
7*f4a2713aSLionel Sambuc int (*FPL) (int) = FP; // C doesn't consider this an error.
8*f4a2713aSLionel Sambuc
9*f4a2713aSLionel Sambuc // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
10*f4a2713aSLionel Sambuc int (^PFR) (int) = IFP; // OK
11*f4a2713aSLionel Sambuc PFR = II; // OK
12*f4a2713aSLionel Sambuc
13*f4a2713aSLionel Sambuc int (^IFP) () = PFR; // OK
14*f4a2713aSLionel Sambuc
15*f4a2713aSLionel Sambuc
16*f4a2713aSLionel Sambuc const int (^CIC) () = IFP; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}}
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambuc const int (^CICC) () = CIC;
19*f4a2713aSLionel Sambuc
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc int * const (^IPCC) () = 0;
22*f4a2713aSLionel Sambuc
23*f4a2713aSLionel Sambuc int * const (^IPCC1) () = IPCC;
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambuc int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *(^)()' with an expression of type 'int *const (^)()'}}
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambuc int (^IPCC3) (const int) = PFR;
28*f4a2713aSLionel Sambuc
29*f4a2713aSLionel Sambuc int (^IPCC4) (int, char (^CArg) (double));
30*f4a2713aSLionel Sambuc
31*f4a2713aSLionel Sambuc int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
32*f4a2713aSLionel Sambuc
33*f4a2713aSLionel Sambuc int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(float))' with an expression of type 'int (^)(int, char (^)(double))'}}
34*f4a2713aSLionel Sambuc
35*f4a2713aSLionel Sambuc IPCC2 = 0;
36*f4a2713aSLionel Sambuc IPCC2 = 1; // expected-error {{invalid block pointer conversion assigning to 'int *(^)()' from 'int'}}
37*f4a2713aSLionel Sambuc int (^x)() = 0;
38*f4a2713aSLionel Sambuc int (^y)() = 3; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
39*f4a2713aSLionel Sambuc int a = 1;
40*f4a2713aSLionel Sambuc int (^z)() = a+4; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc
blah()43*f4a2713aSLionel Sambuc int blah() {
44*f4a2713aSLionel Sambuc int (^IFP) (float);
45*f4a2713aSLionel Sambuc char (^PCP)(double, double, char);
46*f4a2713aSLionel Sambuc
47*f4a2713aSLionel Sambuc IFP(1.0);
48*f4a2713aSLionel Sambuc IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
49*f4a2713aSLionel Sambuc
50*f4a2713aSLionel Sambuc char ch = PCP(1.0, 2.0, 'a');
51*f4a2713aSLionel Sambuc return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
52*f4a2713aSLionel Sambuc }
53