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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/* { dg-do compile } */
/* { dg-options "-std=c2y -pedantic-errors" } */
#define NULL ((void *) 0)
extern int x[];
static int w[] = {1, 2, 3};
void
completed (void)
{
int i = 42;
int a[] = {1, 2, i};
_Static_assert(_Countof (w) == 3);
_Static_assert(_Countof (a) == 3);
}
void
incomplete (int p[])
{
_Countof (x); /* { dg-error "incomplete" } */
/* We want to support array parameters in the future,
which should change this from "invalid" to "incomplete". */
_Countof (p); /* { dg-error "invalid" } */
}
void
fam (void)
{
struct {
int x;
int fam[];
} s;
_Countof (s.fam); /* { dg-error "incomplete" } */
}
void
param (int n, int p[n])
{
/* We want to support array parameters in the future,
which would make this work. */
_Countof (p); /* { dg-error "invalid" } */
}
void fix_fix (int i, char (*a)[3][5], int (*x)[_Countof (*a)],
short (*)[_Generic(x, int (*)[3]: 1)]);
void fix_var (int i, char (*a)[3][i], int (*x)[_Countof (*a)],
short (*)[_Generic(x, int (*)[3]: 1)]);
void fix_uns (int i, char (*a)[3][*], int (*x)[_Countof (*a)],
short (*)[_Generic(x, int (*)[3]: 1)]);
void
func (void)
{
int i3[3];
int i5[5];
char c35[3][5];
fix_fix (5, &c35, &i3, NULL);
fix_fix (5, &c35, &i5, NULL); /* { dg-error "incompatible-pointer-types" } */
fix_var (5, &c35, &i3, NULL);
fix_var (5, &c35, &i5, NULL); /* { dg-error "incompatible-pointer-types" } */
fix_uns (5, &c35, &i3, NULL);
fix_uns (5, &c35, &i5, NULL); /* { dg-error "incompatible-pointer-types" } */
}
void
non_arr(void)
{
int x;
int *p;
struct s {
int x[3];
} s;
_Countof (x); /* { dg-error "invalid" } */
_Countof (int); /* { dg-error "invalid" } */
_Countof (s); /* { dg-error "invalid" } */
_Countof (struct s); /* { dg-error "invalid" } */
_Countof (&x); /* { dg-error "invalid" } */
_Countof (p); /* { dg-error "invalid" } */
_Countof (int *); /* { dg-error "invalid" } */
_Countof (&s.x); /* { dg-error "invalid" } */
_Countof (int (*)[3]); /* { dg-error "invalid" } */
}
static int f1();
static int f2(); /* { dg-error "never defined" } */
int a[10][9];
int n;
void
syms(void)
{
int b[n][n];
_Countof (a[f1()]);
_Countof (b[f2()]);
}
void
no_parens(void)
{
_Static_assert(_Countof a == 10);
_Static_assert(_Countof *a == 9);
_Static_assert(_Countof (int [3]) {} == 3);
_Countof int [3]; /* { dg-error "expected expression before" } */
}
void
const_expr(void)
{
int n = 7;
_Static_assert (_Countof (int [3][n]) == 3);
_Static_assert (_Countof (int [n][3]) == 7); /* { dg-error "not constant" } */
}
|