1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks 2dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 3dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroffint (*FP)(); 4dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroffint (^IFP) (); 5dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroffint (^II) (int); 6dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroffint main() { 7dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff int (*FPL) (int) = FP; // C doesn't consider this an error. 81eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error. 10687abffee40d0459fe5eecf3e5ee6e60be69d93cEli Friedman int (^PFR) (int) = IFP; // OK 111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PFR = II; // OK 12dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int (^IFP) () = PFR; // OK 14dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 15dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 16d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian const int (^CIC) () = IFP; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}} 175291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 185495f37302f7c82192dab1ce8d9c9fe76ed0ee37Chandler Carruth const int (^CICC) () = CIC; 19dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 20dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int * const (^IPCC) () = 0; 22dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int * const (^IPCC1) () = IPCC; 24dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 2508a41901e18aeb91b87d031b93df70374af02564Douglas Gregor int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *(^)()' with an expression of type 'int *const (^)()'}} 26dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int (^IPCC3) (const int) = PFR; 28dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int (^IPCC4) (int, char (^CArg) (double)); 30dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int (^IPCC5) (int, char (^CArg) (double)) = IPCC4; 32dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 3308a41901e18aeb91b87d031b93df70374af02564Douglas Gregor 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))'}} 34dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IPCC2 = 0; 36d4eea8362605807327735727a9098abe1eb23b19Douglas Gregor IPCC2 = 1; // expected-error {{invalid block pointer conversion assigning to 'int *(^)()' from 'int'}} 371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int (^x)() = 0; 3808a41901e18aeb91b87d031b93df70374af02564Douglas Gregor int (^y)() = 3; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}} 391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int a = 1; 4008a41901e18aeb91b87d031b93df70374af02564Douglas Gregor int (^z)() = a+4; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}} 41dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff} 42dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 43dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroffint blah() { 441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump int (^IFP) (float); 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump char (^PCP)(double, double, char); 46dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IFP(1.0); 481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IFP (1.0, 2.0); // expected-error {{too many arguments to block call}} 49dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump char ch = PCP(1.0, 2.0, 'a'); 511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PCP(1.0, 2.0); // expected-error {{too few arguments to block}} 52dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff} 53