array-constraint.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
  2. struct s; // expected-note 2 {{forward declaration of 'struct s'}}
  3. struct s* t (struct s z[]) { // expected-error {{array has incomplete element type}}
  4. return z;
  5. }
  6. void ff() {
  7. struct s v, *p; // expected-error {{variable has incomplete type 'struct s'}}
  8. p = &v;
  9. }
  10. void *k (void l[2]) { // expected-error {{array has incomplete element type}}
  11. return l;
  12. }
  13. struct vari {
  14. int a;
  15. int b[];
  16. };
  17. struct vari *func(struct vari a[]) { // expected-warning {{'struct vari' may not be used as an array element due to flexible array member}}
  18. return a;
  19. }
  20. int foo[](void); // expected-error {{'foo' declared as array of functions}}
  21. int foo2[1](void); // expected-error {{'foo2' declared as array of functions}}
  22. typedef int (*pfunc)(void);
  23. pfunc xx(int f[](void)) { // expected-error {{'f' declared as array of functions}}
  24. return f;
  25. }
  26. void check_size() {
  27. float f;
  28. int size_not_int[f]; // expected-error {{size of array has non-integer type 'float'}}
  29. int negative_size[1-2]; // expected-error{{array with a negative size}}
  30. int zero_size[0]; // expected-warning{{zero size arrays are an extension}}
  31. }
  32. static int I;
  33. typedef int TA[I]; // expected-error {{variable length array declaration not allowed at file scope}}
  34. void strFunc(char *); // expected-note{{passing argument to parameter here}}
  35. const char staticAry[] = "test";
  36. void checkStaticAry() {
  37. strFunc(staticAry); // expected-warning{{passing 'const char [5]' to parameter of type 'char *' discards qualifiers}}
  38. }