static-array.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
  2. void cat0(int a[static 0]) {} // expected-warning {{'static' has no effect on zero-length arrays}}
  3. void cat(int a[static 3]) {} // expected-note 2 {{callee declares array parameter as static here}}
  4. void vat(int i, int a[static i]) {} // expected-note {{callee declares array parameter as static here}}
  5. void f(int *p) {
  6. int a[2], b[3], c[4];
  7. cat0(0);
  8. cat(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
  9. cat(a); // expected-warning {{array argument is too small; contains 2 elements, callee requires at least 3}}
  10. cat(b);
  11. cat(c);
  12. cat(p);
  13. vat(1, 0); // expected-warning {{null passed to a callee that requires a non-null argument}}
  14. vat(3, b);
  15. }
  16. typedef int td[static 3]; // expected-error {{'static' used in array declarator outside of function prototype}}
  17. typedef void(*fp)(int[static 42]); // no-warning
  18. void g(void) {
  19. int a[static 42]; // expected-error {{'static' used in array declarator outside of function prototype}}
  20. int b[const 10]; // expected-error {{type qualifier used in array declarator outside of function prototype}}
  21. int c[volatile 10]; // expected-error {{type qualifier used in array declarator outside of function prototype}}
  22. int d[restrict 10]; // expected-error {{type qualifier used in array declarator outside of function prototype}}
  23. int e[static restrict 1]; // expected-error {{'static' used in array declarator outside of function prototype}}
  24. }
  25. void h(int [static const 10][42]); // no-warning
  26. void i(int [10]
  27. [static 42]); // expected-error {{'static' used in non-outermost array type derivation}}
  28. void j(int [10]
  29. [const 42]); // expected-error {{type qualifier used in non-outermost array type derivation}}
  30. void k(int (*x)[static 10]); // expected-error {{'static' used in non-outermost array type derivation}}
  31. void l(int (x)[static 10]); // no-warning
  32. void m(int *x[static 10]); // no-warning
  33. void n(int *(x)[static 10]); // no-warning
  34. void o(int (x[static 10])(void)); // expected-error{{'x' declared as array of functions of type 'int (void)'}}
  35. void p(int (^x)[static 10]); // expected-error{{block pointer to non-function type is invalid}}
  36. void q(int (^x[static 10])()); // no-warning
  37. void r(x)
  38. int x[restrict]; // no-warning
  39. {}