aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wvla-parameter-4.c
blob: 599ad19a3e43b2715717716c2ecab4c3a8cb3936 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* PR c/50584 - No warning for passing small array to C99 static array
   declarator
   Verify warnings for redeclarations of functions with pointer parameters
   to arrays with variable bounds involving typedefs.
   { dg-do compile }
   { dg-options "-Wall -Wvla-parameter" } */

extern int m, n;

typedef int IA3[3];

/* Verify the warning points to the declaration with more unspecified
   bounds, guiding the user to specify them rather than making them all
   unspecified.  */
void* f_pIA3ax (IA3 *x[*]);             // { dg-warning "argument 1 of type 'int \\\(\\\*\\\[\\\*]\\\)\\\[3]' .aka '\[^\n\r\}\]+'. declared with 1 unspecified variable bound" }
void* f_pIA3ax (IA3 *x[*]);
void* f_pIA3ax (IA3 *x[n]);             // { dg-message "subsequently declared as 'int \\\(\\\*\\\[n]\\\)\\\[3]' with 0 unspecified variable bounds" "note" }
void* f_pIA3ax (IA3 *x[n]) { return x; }


void* f_pIA3an (IA3 *x[n]);              // { dg-message "previously declared as 'int \\\(\\\*\\\[n]\\\)\\\[3]' with 0 unspecified variable bounds" "note" }
void* f_pIA3an (IA3 *x[n]);
void* f_pIA3an (IA3 *x[*]);              // { dg-warning "argument 1 of type 'int \\\(\\\*\\\[\\\*]\\\)\\\[3]' .aka '\[^\n\r\}\]+'. declared with 1 unspecified variable bound" }
void* f_pIA3an (IA3 *x[n]) { return x; }


void nowarn_local_fndecl (void)
{
  typedef int IAm[m];

  void* f_IAm (IAm);
  void* f_IAm (int[m]);
  void* f_IAm (IAm);

  void* f_iam (int[m]);
  void* f_iam (IAm);
  void* f_iam (int[m]);

  typedef int     IA3[3];
  typedef IA3     IAn_3[n];
  typedef IAn_3   IA2_n_3[2];
  typedef IA2_n_3 IAm_2_n_3[m];

  void f_IAm_2_n_3 (IAm_2_n_3);
  void f_IAm_2_n_3 (IA2_n_3[m]);
  void f_IAm_2_n_3 (IAn_3[m][2]);
  void f_IAm_2_n_3 (IA3[m][2][n]);
  void f_IAm_2_n_3 (int[m][2][n][3]);

  void f_iam_2_n_3 (int[m][2][n][3]);
  void f_iam_2_n_3 (IA3[m][2][n]);
  void f_iam_2_n_3 (IAn_3[m][2]);
  void f_iam_2_n_3 (IAm_2_n_3);

  void f_IAx_m_2_n_3 (IAm_2_n_3[*]);
  void f_IAx_m_2_n_3 (IA2_n_3[*][m]);
  void f_IAx_m_2_n_3 (IAn_3[*][m][2]);
  void f_IAx_m_2_n_3 (IA3[*][m][2][n]);
  void f_IAx_m_2_n_3 (int[*][m][2][n][3]);

  void f_IA__m_2_n_3 (IAm_2_n_3[]);
  void f_IA__m_2_n_3 (IA2_n_3[][m]);
  void f_IA__m_2_n_3 (IAn_3[][m][2]);
  void f_IA__m_2_n_3 (IA3[][m][2][n]);
  void f_IA__m_2_n_3 (int[][m][2][n][3]);
}


void warn_local_fndecl (void)
{
  typedef int IAm[m];
  typedef int IAn[n];

  void* g_IAm (IAm);                    // { dg-message "previously declared as 'int\\\[m]' with bound 'm'" }
  void* g_IAm (int[n]);                 // { dg-warning "argument 1 of type 'int\\\[n]' declared with mismatched bound 'n'" }
  void* g_IAm (IAm);

  void* g_iam (int[m]);                 // { dg-message "previously declared as 'int\\\[m]' with bound 'm'" }
  void* g_iam (IAn);                    // { dg-warning "argument 1 of type 'int\\\[n]' declared with mismatched bound 'n'" }
  void* g_iam (int[m]);


  typedef int     IA3[3];
  typedef IA3     IAn_3[n];
  typedef IAn_3   IA2_n_3[2];
  typedef IA2_n_3 IAm_2_n_3[m];

  typedef IA3     IAm_3[m];
  typedef IAm_3   IA2_m_3[2];
  typedef IA2_m_3 IAm_2_m_3[m];

  void* g_IAm_2_n_3 (IAm_2_n_3);
  void* g_IAm_2_n_3 (int[m][2][m][3]);  // { dg-warning "argument 1 of type 'int\\\[m]\\\[2]\\\[m]\\\[3]' declared with mismatched bound 'm'" }
  void* g_IAm_2_n_3 (IAm_2_n_3);

  void* g_iam_2_n_2 (int[m][2][n][3]);
  void* g_iam_2_n_2 (IAm_2_m_3);        // { dg-warning "argument 1 of type 'int\\\[m]\\\[2]\\\[m]\\\[3]' declared with mismatched bound 'm'" }
  void* g_iam_2_n_2 (int[m][2][n][3]);
}