blob: 2aa1422dd915637936f2bfb08340d28181b4c9cd [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
Steve Naroffdd972f22008-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 Stump1eb44332009-09-09 15:08:12 +00008
Steve Naroffdd972f22008-09-05 22:11:13 +00009 // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
Eli Friedman687abff2009-06-08 04:24:21 +000010 int (^PFR) (int) = IFP; // OK
Mike Stump1eb44332009-09-09 15:08:12 +000011 PFR = II; // OK
Steve Naroffdd972f22008-09-05 22:11:13 +000012
Mike Stump1eb44332009-09-09 15:08:12 +000013 int (^IFP) () = PFR; // OK
Steve Naroffdd972f22008-09-05 22:11:13 +000014
15
Fariborz Jahaniand263fd12011-02-11 18:46:17 +000016 const int (^CIC) () = IFP; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000017
Chandler Carruth5495f372010-07-14 06:36:18 +000018 const int (^CICC) () = CIC;
Douglas Gregor5291c3c2010-07-13 08:18:22 +000019
Steve Naroffdd972f22008-09-05 22:11:13 +000020
Mike Stump1eb44332009-09-09 15:08:12 +000021 int * const (^IPCC) () = 0;
Steve Naroffdd972f22008-09-05 22:11:13 +000022
Mike Stump1eb44332009-09-09 15:08:12 +000023 int * const (^IPCC1) () = IPCC;
Steve Naroffdd972f22008-09-05 22:11:13 +000024
Douglas Gregor08a41902010-04-09 17:53:29 +000025 int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *(^)()' with an expression of type 'int *const (^)()'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000026
Mike Stump1eb44332009-09-09 15:08:12 +000027 int (^IPCC3) (const int) = PFR;
Steve Naroffdd972f22008-09-05 22:11:13 +000028
Mike Stump1eb44332009-09-09 15:08:12 +000029 int (^IPCC4) (int, char (^CArg) (double));
Steve Naroffdd972f22008-09-05 22:11:13 +000030
Mike Stump1eb44332009-09-09 15:08:12 +000031 int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
Steve Naroffdd972f22008-09-05 22:11:13 +000032
Douglas Gregor08a41902010-04-09 17:53:29 +000033 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))'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000034
Mike Stump1eb44332009-09-09 15:08:12 +000035 IPCC2 = 0;
Douglas Gregord4eea832010-04-09 00:35:39 +000036 IPCC2 = 1; // expected-error {{invalid block pointer conversion assigning to 'int *(^)()' from 'int'}}
Mike Stump1eb44332009-09-09 15:08:12 +000037 int (^x)() = 0;
Douglas Gregor08a41902010-04-09 17:53:29 +000038 int (^y)() = 3; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
Mike Stump1eb44332009-09-09 15:08:12 +000039 int a = 1;
Douglas Gregor08a41902010-04-09 17:53:29 +000040 int (^z)() = a+4; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
Steve Naroffdd972f22008-09-05 22:11:13 +000041}
42
43int blah() {
Mike Stump1eb44332009-09-09 15:08:12 +000044 int (^IFP) (float);
45 char (^PCP)(double, double, char);
Steve Naroffdd972f22008-09-05 22:11:13 +000046
Mike Stump1eb44332009-09-09 15:08:12 +000047 IFP(1.0);
48 IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
Steve Naroffdd972f22008-09-05 22:11:13 +000049
Mike Stump1eb44332009-09-09 15:08:12 +000050 char ch = PCP(1.0, 2.0, 'a');
51 return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
Steve Naroffdd972f22008-09-05 22:11:13 +000052}