1 /* PR c/50584 - No warning for passing small array to C99 static array
2 declarator
3 Verify the -Wvla-parameter warnings correctly diagnose mismatches
4 between one-dimensional VLA and non-VLA arguments in redeclarations
5 of the same function.
6 Also verify that the array/pointer argument form in a mismatched
7 redeclaration doesn't override the form in the initial declaration.
8 { dg-do compile }
9 { dg-options "-Wall -Wvla-parameter" } */
10
11 /* Verify that redeclaring an argument as a VLA with an unspecified
12 bound that was first declared as an ordinary array with an unspecified
13 bound triggers a warning. */
14 void f1ia_x (int[]); // { dg-message "previously declared as an ordinary array 'int\\\[]'" "note" }
15 void f1ia_x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
16 void f1ia_x (int[]);
17 void f1ia_x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
18 /* Also verify that a definition of the same form as the first declaration
19 doesn't trigger a warning and doesn't prevent warnings for subsequent
20 mismatches. */
21 void f1ia_x (int a[]) { (void)&a;}
22 void f1ia_x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
23
24 /* Repeat the above but starting with an ordinary array with a constant
25 bound. */
26 void f1ia1x (int[1]); // { dg-message "previously declared as an ordinary array 'int\\\[1]'" "note" }
27 void f1ia1x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
28 void f1ia1x (int a[1]) { (void)&a; }
29 void f1ia1x (int[1]);
30 void f1ia1x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
31
32 void f1ipx (int*); // { dg-message "previously declared as a pointer 'int ?\\\*'" "note" }
33 void f1ipx (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
34 void f1ipx (int*);
35 void f1ipx (int *p) { (void)&p; }
36 void f1ipx (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
37 void f1ipx (int*);
38
39 void f2ipx (int*, int*); // { dg-message "previously declared as a pointer 'int ?\\\*'" "note" }
40 void f2ipx (int*, int[*]); // { dg-warning "argument 2 of type 'int\\\[\\\*]' declared as a variable length array" }
41 void f2ipx (int*, int*);
42 void f2ipx (int*, int[*]); // { dg-warning "argument 2 of type 'int\\\[\\\*]' declared as a variable length array" }
43 void f2ipx (int *p, int *q) { (void)&p; (void)&q; }
44 void f2ipx (int*, int[*]); // { dg-warning "argument 2 of type 'int\\\[\\\*]' declared as a variable length array" }
45
46 void f1ias2x (int[static 2]); // { dg-message "previously declared as an ordinary array 'int\\\[static 2]'" }
47 void f1ias2x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
48 void f1ias2x (int[static 2]);
49 void f1ias2x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
50 void f1ias2x (int a[static 2]) { (void)&a; }
51 void f1ias2x (int[*]); // { dg-warning "argument 1 of type 'int\\\[\\\*]' declared as a variable length array" }
52 void f1ias2x (int[static 2]);
53
54 extern int nelts;
55
56 void f1sa_var (short[]); // { dg-message "previously declared as an ordinary array 'short int\\\[]'" }
57 void f1sa_var (short[nelts]); // { dg-warning "argument 1 of type 'short int\\\[nelts]' declared as a variable length array" }
58 void f1sa_var (short[]);
59 void f1sa_var (short[nelts]); // { dg-warning "argument 1 of type 'short int\\\[nelts]' declared as a variable length array" }
60 void f1sa_var (short a[]) { (void)&a; }
61 void f1sa_var (short[nelts]); // { dg-warning "argument 1 of type 'short int\\\[nelts]' declared as a variable length array" }
62 void f1sa_var (short[]);
63
64 void f1sa_expr (int[]); // { dg-message "previously declared as an ordinary array 'int\\\[]'" }
65 void f1sa_expr (int[nelts + 1]); // { dg-warning "argument 1 of type 'int\\\[nelts \\\+ 1]' declared as a variable length array" }
66 void f1sa_expr (int[]);
67 void f1sa_expr (int[nelts * 2]); // { dg-warning "argument 1 of type 'int\\\[nelts \\\* 2]' declared as a variable length array" }
68 void f1sa_expr (int a[]) { (void)&a; }
69 void f1sa_expr (int[nelts / 3]); // { dg-warning "argument 1 of type 'int\\\[nelts / 3]' declared as a variable length array" }
70 void f1sa_expr (int[]);
71
72 extern int f (int);
73
74 void f1ia_f (int[]); // { dg-message "previously declared as an ordinary array 'int\\\[]'" }
75 void f1ia_f (int[f (1)]); // { dg-warning "argument 1 of type 'int\\\[f *\\\(1\\\)]' declared as a variable length array" }
76 void f1ia_f (int[]);
77 void f1ia_f (int[f (2)]); // { dg-warning "argument 1 of type 'int\\\[f *\\\(2\\\)]' declared as a variable length array" }
78 void f1ia_f (int a[]) { (void)&a; }
79 void f1ia_f (int[f (3)]); // { dg-warning "argument 1 of type 'int\\\[f *\\\(3\\\)]' declared as a variable length array" }
80 void f1ia_f (int[f (4)]); // { dg-warning "argument 1 of type 'int\\\[f *\\\(4\\\)]' declared as a variable length array" }
81 void f1ia_f (int[]);
82
83 void f1iaf0_f1 (int[f (0)]); // { dg-message "previously declared as 'int\\\[f *\\\(0\\\)]'" }
84 void f1iaf0_f1 (int[f (1)]); // { dg-warning "argument 1 of type 'int\\\[f *\\\(1\\\)]' declared with mismatched bound" }
85 void f1iaf0_f1 (int[f (0)]);
86 void f1iaf0_f1 (int[f (1)]); // { dg-warning "argument 1 of type 'int\\\[f *\\\(1\\\)]' declared with mismatched bound" }
87 void f1iaf0_f1 (int a[f (0)]) { (void)&a; }
88 void f1iaf0_f1 (int[f (1)]); // { dg-warning "argument 1 of type 'int\\\[f *\\\(1\\\)]' declared with mismatched bound" }
89 void f1iaf0_f1 (int[f (0)]);
90
91 void f1la_ (long[]); // { dg-message "previously declared as an ordinary array 'long int\\\[]'" }
92 void f1la_ (long[nelts]); // { dg-warning "argument 1 of type 'long int\\\[nelts]' declared as a variable length array" }
93 void f1la_ (long[]);
94 void f1la_ (long a[nelts]) // { dg-warning "argument 1 of type 'long int\\\[nelts]' declared as a variable length array" }
95 { (void)&a; }
96 void f1la_ (long[]);
97
98 void f2ca_ (int, char[]); // { dg-message "previously declared as an ordinary array 'char\\\[]'" }
99 void f2ca_ (int n, char[n]); // { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array" }
100 void f2ca_ (int, char[]);
101 void f2ca_ (int n, char a[n]) // { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array" }
102 { (void)&n; (void)&a; }
103
104 void f2ia1_f (int n, int[n]); // { dg-message "previously declared as 'int\\\[n]' with bound argument 1" }
105 void f2ia1_f (int, int[f (0)]); // { dg-warning "argument 2 of type 'int\\\[f *\\\(0\\\)]' declared with mismatched bound 'f *\\\(0\\\)'" }
106 void f2ia1_f (int m, int[m]);
107 void f2ia1_f (int, int[f (1)]); // { dg-warning "argument 2 of type 'int\\\[f *\\\(1\\\)]' declared with mismatched bound 'f *\\\(1\\\)'" }
108 void f2ia1_f (int x, int a[x]) { (void)&x; (void)&a; }
109 void f2ia1_f (int, int[f (2)]); // { dg-warning "argument 2 of type 'int\\\[f *\\\(2\\\)]' declared with mismatched bound 'f *\\\(2\\\)'" }
110 void f2ia1_f (int y, int[y]);
111
112 void f2iaf_1 (int, int[f (0)]); // { dg-message "previously declared as 'int\\\[f *\\\(0\\\)]'" }
113 void f2iaf_1 (int n, int[n]); // { dg-warning "argument 2 of type 'int\\\[n]' declared with mismatched bound argument 1" }
114 void f2iaf_1 (int, int[f (0)]);
115 void f2iaf_1 (int m, int[m]); // { dg-warning "argument 2 of type 'int\\\[m]' declared with mismatched bound argument 1" }
116 void f2iaf_1 (int x, int a[f (0)]) { (void)&x; (void)&a; }
117 void f2iaf_1 (int y, int[y]); // { dg-warning "argument 2 of type 'int\\\[y]' declared with mismatched bound argument 1" }
118
119
120 void f3ia1 (int n, int, int[n]); // { dg-message "previously declared as 'int\\\[n]' with bound argument 1" }
121 void f3ia1 (int, int n, int[n]); // { dg-warning "argument 3 of type 'int\\\[n]' declared with mismatched bound argument 2" }
122 void f3ia1 (int n, int, int[n]);
123
124
125 extern int g (int);
126
127 void f1iaf_g (int[f (1)]); // { dg-message "previously declared as 'int\\\[f *\\\(1\\\)]'" }
128 void f1iaf_g (int[g (1)]); // { dg-warning "argument 1 of type 'int\\\[g *\\\(1\\\)]' declared with mismatched bound" }
129 void f1iaf_g (int[f (1)]);
130
131
132 void nrf1iaf_g (int[f (1)]); // { dg-message "previously declared as 'int\\\[f *\\\(1\\\)]'" }
133 __attribute__ ((nonnull))
134 void nrf1iaf_g (int[g (1)]); // { dg-warning "argument 1 of type 'int\\\[g *\\\(1\\\)]' declared with mismatched bound" }
135 __attribute__ ((noreturn))
136 void nrf1iaf_g (int[f (1)]);