2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
2008-09-06 06:11:13 +08:00
int ( * FP ) ( ) ;
int ( ^ IFP ) ( ) ;
int ( ^ II ) ( int ) ;
int main ( ) {
int ( * FPL ) ( int ) = FP ; // C doesn't consider this an error.
2009-09-09 23:08:12 +08:00
2008-09-06 06:11:13 +08:00
// For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
2009-06-08 12:24:21 +08:00
int ( ^ PFR ) ( int ) = IFP ; // OK
2009-09-09 23:08:12 +08:00
PFR = II ; // OK
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
int ( ^ IFP ) ( ) = PFR ; // OK
2008-09-06 06:11:13 +08:00
2011-02-12 02:46:17 +08:00
const int ( ^ CIC ) ( ) = IFP ; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}}
2010-07-13 16:18:22 +08:00
2010-07-14 14:36:18 +08:00
const int ( ^ CICC ) ( ) = CIC ;
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
int * const ( ^ IPCC ) ( ) = 0 ;
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
int * const ( ^ IPCC1 ) ( ) = IPCC ;
2008-09-06 06:11:13 +08:00
2010-04-10 01:53:29 +08:00
int * ( ^ IPCC2 ) ( ) = IPCC ; // expected-error {{incompatible block pointer types initializing 'int *(^)()' with an expression of type 'int *const (^)()'}}
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
int ( ^ IPCC3 ) ( const int ) = PFR ;
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
int ( ^ IPCC4 ) ( int , char ( ^ CArg ) ( double ) ) ;
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
int ( ^ IPCC5 ) ( int , char ( ^ CArg ) ( double ) ) = IPCC4 ;
2008-09-06 06:11:13 +08:00
2010-04-10 01:53:29 +08:00
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))'}}
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
IPCC2 = 0 ;
2020-02-25 22:49:59 +08:00
IPCC1 = 1 ; // expected-error {{invalid block pointer conversion assigning to 'int *const (^)()' from 'int'}}
2009-09-09 23:08:12 +08:00
int ( ^ x ) ( ) = 0 ;
2010-04-10 01:53:29 +08:00
int ( ^ y ) ( ) = 3 ; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
2009-09-09 23:08:12 +08:00
int a = 1 ;
2010-04-10 01:53:29 +08:00
int ( ^ z ) ( ) = a + 4 ; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
2008-09-06 06:11:13 +08:00
}
int blah ( ) {
2009-09-09 23:08:12 +08:00
int ( ^ IFP ) ( float ) ;
char ( ^ PCP ) ( double , double , char ) ;
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
IFP ( 1.0 ) ;
IFP ( 1.0 , 2.0 ) ; // expected-error {{too many arguments to block call}}
2008-09-06 06:11:13 +08:00
2009-09-09 23:08:12 +08:00
char ch = PCP ( 1.0 , 2.0 , ' a ' ) ;
return PCP ( 1.0 , 2.0 ) ; // expected-error {{too few arguments to block}}
2008-09-06 06:11:13 +08:00
}