| 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 multimensional array arguments with one or more variable |
| 5 |
bounds in redeclarations of the same function. |
| 6 |
{ dg-do compile } |
| 7 |
{ dg-options "-Wall -Wvla-parameter" } */ |
| 8 |
|
| 9 |
void fmn_a1n_axn (int n, int[1][n]); // { dg-message "previously declared as 'int\\\[1]\\\[n]' with 1 variable bound" "note" } |
| 10 |
void fmn_a1n_axn (int n, int[*][n]); // { dg-warning "argument 2 of type 'int\\\[\\\*]\\\[n]' declared with 2 variable bounds" } |
| 11 |
|
| 12 |
|
| 13 |
void fmn_axn_a2n (int n, int[*][n]); // { dg-message "previously declared as 'int\\\[\\\*]\\\[n]' with 2 variable bounds" "note" } |
| 14 |
void fmn_axn_a2n (int n, int[2][n]); // { dg-warning "argument 2 of type 'int\\\[2]\\\[n]' declared with 1 variable bound" } |
| 15 |
|
| 16 |
|
| 17 |
void fmn_amn_axn (int m, int n, int[m][n]); // { dg-message "previously declared as 'int\\\[m]\\\[n]' with 0 unspecified variable bounds" "note" } |
| 18 |
void fmn_amn_axn (int m, int n, int[*][n]); // { dg-warning "argument 3 of type 'int\\\[\\\*]\\\[n]' declared with 1 unspecified variable bound" } |
| 19 |
|
| 20 |
// Same as above but a different function name. |
| 21 |
void gmn_amn_axn (int m, int n, int[m][n]); // { dg-message "previously declared as 'int\\\[m]\\\[n]' with 0 unspecified variable bounds" "note" } |
| 22 |
void gmn_amn_axn (int m, int n, int[*][n]); // { dg-warning "argument 3 of type 'int\\\[\\\*]\\\[n]' declared with 1 unspecified variable bound" } |
| 23 |
|
| 24 |
typedef int A7[7]; |
| 25 |
|
| 26 |
void fm_A7_m_5 (int m, A7[m][5]); // { dg-message "previously declared as 'int\\\[m]\\\[5]\\\[7]' with bound argument 1" "note" } |
| 27 |
void fm_A7_m_5 (int n, A7[n][5]); |
| 28 |
|
| 29 |
void fm_A7_m_5 (int n, A7[n + 1][5]); // { dg-warning "argument 2 of type 'int\\\[n \\\+ 1]\\\[5]\\\[7]' declared with mismatched bound 'n \\\+ 1'" } |
| 30 |
|
| 31 |
|
| 32 |
int n1, n2, n3, n4, n5, n6, n7, n8, n9; |
| 33 |
void f (int[n1][2][n3][4][n5][6][n7][8][n9]); // { dg-message "previously declared as 'int\\\[n1]\\\[2]\\\[n3]\\\[4]\\\[n5]\\\[6]\\\[n7]\\\[8]\\\[n9]' with 0 unspecified variable bounds" "note" } |
| 34 |
// { dg-message "with 5 variable bounds" "note" { target *-*-* } .-1 } |
| 35 |
void f (int[n1][2][n3][4][n5][6][n7][8][n9]); |
| 36 |
|
| 37 |
void f (int[n1][2][n3][4][n5][6][n7][8][*]); // { dg-warning "argument 1 of type 'int\\\[n1]\\\[2]\\\[n3]\\\[4]\\\[n5]\\\[6]\\\[n7]\\\[8]\\\[\\\*]' declared with 1 unspecified variable bound" "pr100420 (expected)" { target *-*-* } } |
| 38 |
void f (int[n1][2][n3][4][n5][6][*][8][n9]); // { dg-warning "argument 1 of type 'int\\\[n1]\\\[2]\\\[n3]\\\[4]\\\[n5]\\\[6]\\\[\\\*]\\\[8]\\\[n9]' declared with 1 unspecified variable bound" "pr100420 (expected)" { target *-*-* } } |
| 39 |
void f (int[n1][2][n3][4][*][6][n7][8][n9]); // { dg-warning "argument 1 of type 'int\\\[n1]\\\[2]\\\[n3]\\\[4]\\\[\\\*]\\\[6]\\\[n7]\\\[8]\\\[n9]' declared with 1 unspecified variable bound" "pr100420 (expected)" { target *-*-*} } |
| 40 |
void f (int[n1][2][*][4][n5][6][n7][8][n9]); // { dg-warning "argument 1 of type 'int\\\[n1]\\\[2]\\\[\\\*]\\\[4]\\\[n5]\\\[6]\\\[n7]\\\[8]\\\[n9]' declared with 1 unspecified variable bound" "pr100420 (expected)" { target *-*-* } } |
| 41 |
void f (int[*][2][n3][4][n5][6][n7][8][n9]); // { dg-warning "argument 1 of type 'int\\\[\\\*]\\\[2]\\\[n3]\\\[4]\\\[n5]\\\[6]\\\[n7]\\\[8]\\\[n9]' declared with 1 unspecified variable bound" } |
| 42 |
|
| 43 |
void f (int[n1][n2][n3][n4][n5][n6][n7][n8][n9]); // { dg-warning "argument 1 of type 'int\\\[n1]\\\[n2]\\\[n3]\\\[n4]\\\[n5]\\\[n6]\\\[n7]\\\[n8]\\\[n9]' declared with 9 variable bounds" } |
| 44 |
|
| 45 |
// Verify that arrays of pointers to arrays...etc are handled correctly. |
| 46 |
void a2pampan (int (*(*(*[2])[n1])[n2])); |
| 47 |
// { dg-message "previously declared as 'int \\\* \\\(\\\* \\\(\\\*\\\[2]\\\)\\\[n1]\\\)\\\[n2]'" "note" { target *-*-* } .-1 } |
| 48 |
void a2pampan (int (*(*(*[2])[n1])[1])); |
| 49 |
// { dg-warning "argument 1 of type 'int \\\* \\\(\\\* \\\(\\\*\\\[2]\\\)\\\[n1]\\\)\\\[1]' declared with 1 variable bound" "" { target *-*-* } .-1 } |
| 50 |
void a2pampan (int (*(*(*[2])[1])[n2])); |
| 51 |
// { dg-warning "argument 1 of type 'int \\\* \\\(\\\* \\\(\\\*\\\[2]\\\)\\\[1]\\\)\\\[n2]' declared with 1 variable bound" "" { target *-*-* } .-1 } |
| 52 |
void a2pampan (int (*(*(*[2])[n1])[n1])); |
| 53 |
// { dg-warning "argument 1 of type 'int \\\* \\\(\\\* \\\(\\\*\\\[2]\\\)\\\[n1]\\\)\\\[n1]' declared with mismatched bound 'n1'" "" { target *-*-* } .-1 } |
| 54 |
void a2pampan (int (*(*(*[2])[n1])[n2])); |
| 55 |
|
| 56 |
|
| 57 |
/* Verify that the presence or absence of static with VLA dooesn't cause |
| 58 |
unwanted warnings. */ |
| 59 |
|
| 60 |
int f2ia1_1 (int n, int [n][n]); // { sg-message "previously declared as 'int\\\[n]\\\[n]' with bound argument 1" } |
| 61 |
int f2ia1_1 (int n, int[static n][n]); |
| 62 |
int f2ia1_1 (int n, int a[static n][n]) { return sizeof *a; } |
| 63 |
int f2ia1_1 (int n, int[static n + 1][n]); // { dg-warning "argument 2 of type 'int\\\[static *n \\\+ 1]\\\[n]' declared with mismatched bound 'n \\\+ 1'" } |
| 64 |
|
| 65 |
int f2ias1_1 (int n, int [static n][n]); // { dg-message "previously declared as 'int\\\[static +n]\\\[n]' with bound argument 1" } |
| 66 |
int f2ias1_1 (int n, int[n][n]); |
| 67 |
int f2ias1_1 (int n, int a[++n][n]) // { dg-warning "argument 2 of type 'int\\\[\\\+\\\+n]\\\[n]' declared with mismatched bound ' ?\\+\\+n'" } |
| 68 |
{ return sizeof *a; } |