blob: 0aba75e14a9a4b1881c92d55029ffc202d46c3ff [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
Steve Naroff8de9c3a2008-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.
Mike Stump11289f42009-09-09 15:08:12 +00008
Steve Naroff8de9c3a2008-09-05 22:11:13 +00009 // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
Eli Friedman9e81b022009-06-08 04:24:21 +000010 int (^PFR) (int) = IFP; // OK
Mike Stump11289f42009-09-09 15:08:12 +000011 PFR = II; // OK
Steve Naroff8de9c3a2008-09-05 22:11:13 +000012
Mike Stump11289f42009-09-09 15:08:12 +000013 int (^IFP) () = PFR; // OK
Steve Naroff8de9c3a2008-09-05 22:11:13 +000014
15
Mike Stump11289f42009-09-09 15:08:12 +000016 const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}}
Steve Naroff8de9c3a2008-09-05 22:11:13 +000017
Mike Stump11289f42009-09-09 15:08:12 +000018 const int (^CICC) () = CIC;
Steve Naroff8de9c3a2008-09-05 22:11:13 +000019
Mike Stump11289f42009-09-09 15:08:12 +000020 int * const (^IPCC) () = 0;
Steve Naroff8de9c3a2008-09-05 22:11:13 +000021
Mike Stump11289f42009-09-09 15:08:12 +000022 int * const (^IPCC1) () = IPCC;
Steve Naroff8de9c3a2008-09-05 22:11:13 +000023
Mike Stump11289f42009-09-09 15:08:12 +000024 int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}}
Steve Naroff8de9c3a2008-09-05 22:11:13 +000025
Mike Stump11289f42009-09-09 15:08:12 +000026 int (^IPCC3) (const int) = PFR;
Steve Naroff8de9c3a2008-09-05 22:11:13 +000027
Mike Stump11289f42009-09-09 15:08:12 +000028 int (^IPCC4) (int, char (^CArg) (double));
Steve Naroff8de9c3a2008-09-05 22:11:13 +000029
Mike Stump11289f42009-09-09 15:08:12 +000030 int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
Steve Naroff8de9c3a2008-09-05 22:11:13 +000031
Mike Stump11289f42009-09-09 15:08:12 +000032 int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(double))', expected 'int (^)(int, char (^)(float))'}}
Steve Naroff8de9c3a2008-09-05 22:11:13 +000033
Mike Stump11289f42009-09-09 15:08:12 +000034 IPCC2 = 0;
35 IPCC2 = 1; // expected-error {{invalid conversion assigning integer 'int', expected block pointer 'int *(^)()'}}
36 int (^x)() = 0;
37 int (^y)() = 3; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
38 int a = 1;
39 int (^z)() = a+4; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
Steve Naroff8de9c3a2008-09-05 22:11:13 +000040}
41
42int blah() {
Mike Stump11289f42009-09-09 15:08:12 +000043 int (^IFP) (float);
44 char (^PCP)(double, double, char);
Steve Naroff8de9c3a2008-09-05 22:11:13 +000045
Mike Stump11289f42009-09-09 15:08:12 +000046 IFP(1.0);
47 IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
Steve Naroff8de9c3a2008-09-05 22:11:13 +000048
Mike Stump11289f42009-09-09 15:08:12 +000049 char ch = PCP(1.0, 2.0, 'a');
50 return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
Steve Naroff8de9c3a2008-09-05 22:11:13 +000051}