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