blob: d519911589a70cd0607fee81d55a8d6326e7a3f9 [file] [log] [blame]
Fariborz Jahaniane3c8c642011-02-12 19:07:46 +00001// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s -fblocks
2
3int (*FP)();
4int (^IFP) ();
5int (^II) (int);
6int 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 int (^IFP) () = PFR; // OK
14
15
16 const int (^CIC) () = IFP; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}}
17
18 const int (^CICC) () = CIC;
19
20
21 int * const (^IPCC) () = 0;
22
23 int * const (^IPCC1) () = IPCC;
24
25 int * (^IPCC2) () = IPCC; // expected-error {{cannot initialize a variable of type 'int *(^)()' with an lvalue of type 'int *const (^)()'}}
26
27 int (^IPCC3) (const int) = PFR;
28
29 int (^IPCC4) (int, char (^CArg) (double));
30
31 int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
32
33 int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{cannot initialize a variable of type 'int (^)(int, char (^)(float))' with an lvalue of type}}
34
35 IPCC2 = 0;
36 IPCC2 = 1;
37 int (^x)() = 0;
38 int (^y)() = 3; // expected-error {{cannot initialize a variable of type 'int (^)()' with an rvalue of type 'int'}}
39 int a = 1;
40 int (^z)() = a+4; // expected-error {{cannot initialize a variable of type 'int (^)()' with an rvalue of type 'int'}}
41}
42
43int blah() {
44 int (^IFP) (float);
45 char (^PCP)(double, double, char);
46
47 IFP(1.0);
48 IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
49
50 char ch = PCP(1.0, 2.0, 'a');
51 return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
52}