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