block-args.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
  2. void take(void*);
  3. void test() {
  4. take(^(int x){});
  5. take(^(int x, int y){});
  6. take(^(int x, int y){});
  7. take(^(int x, // expected-note {{previous declaration is here}}
  8. int x){}); // expected-error {{redefinition of parameter 'x'}}
  9. take(^(int x) { return x+1; });
  10. int (^CP)(int) = ^(int x) { return x*x; };
  11. take(CP);
  12. int arg;
  13. ^{return 1;}();
  14. ^{return 2;}(arg); // expected-error {{too many arguments to block call}}
  15. ^(void){return 3;}(1); // expected-error {{too many arguments to block call}}
  16. ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
  17. ^(int x, ...){return 5;}(arg, arg); // Explicit varargs, ok.
  18. }
  19. int main(int argc, char** argv) {
  20. ^(int argCount) {
  21. argCount = 3;
  22. }(argc);
  23. }
  24. // radar 7528255
  25. void f0() {
  26. ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \
  27. // expected-error {{parameter name omitted}}
  28. }
  29. // rdar://problem/8962770
  30. void test4() {
  31. int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}}
  32. }
  33. // rdar://problem/9170609
  34. void test5_helper(void (^)(int, int[*]));
  35. void test5(void) {
  36. test5_helper(^(int n, int array[n]) {});
  37. }
  38. // Reduced from a problem on platforms where va_list is an array.
  39. struct tag {
  40. int x;
  41. };
  42. typedef struct tag array_ty[1];
  43. void test6(void) {
  44. void (^block)(array_ty) = ^(array_ty arr) { };
  45. array_ty arr;
  46. block(arr);
  47. }