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