block-call.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
  2. int (*FP)();
  3. int (^IFP) ();
  4. int (^II) (int);
  5. int main() {
  6. int (*FPL) (int) = FP; // C doesn't consider this an error.
  7. // For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
  8. int (^PFR) (int) = IFP; // OK
  9. PFR = II; // OK
  10. int (^IFP) () = PFR; // OK
  11. const int (^CIC) () = IFP; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}}
  12. const int (^CICC) () = CIC;
  13. int * const (^IPCC) () = 0;
  14. int * const (^IPCC1) () = IPCC;
  15. int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *(^)()' with an expression of type 'int *const (^)()'}}
  16. int (^IPCC3) (const int) = PFR;
  17. int (^IPCC4) (int, char (^CArg) (double));
  18. int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
  19. 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))'}}
  20. IPCC2 = 0;
  21. IPCC2 = 1; // expected-error {{invalid block pointer conversion assigning to 'int *(^)()' from 'int'}}
  22. int (^x)() = 0;
  23. int (^y)() = 3; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
  24. int a = 1;
  25. int (^z)() = a+4; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}}
  26. }
  27. int blah() {
  28. int (^IFP) (float);
  29. char (^PCP)(double, double, char);
  30. IFP(1.0);
  31. IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
  32. char ch = PCP(1.0, 2.0, 'a');
  33. return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
  34. }