| 1 |
/* Test C23 typeof and typeof_unqual. Valid code. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-std=c23 -pedantic-errors" } */ |
| 4 |
|
| 5 |
int i; |
| 6 |
extern typeof (i) i; |
| 7 |
extern typeof (int) i; |
| 8 |
extern typeof_unqual (i) i; |
| 9 |
extern typeof_unqual (int) i; |
| 10 |
|
| 11 |
volatile int vi; |
| 12 |
extern typeof (volatile int) vi; |
| 13 |
extern typeof (vi) vi; |
| 14 |
|
| 15 |
extern typeof_unqual (volatile int) i; |
| 16 |
extern typeof_unqual (vi) i; |
| 17 |
extern typeof ((const int) vi) i; |
| 18 |
extern typeof ((volatile int) vi) i; |
| 19 |
|
| 20 |
const int ci; |
| 21 |
extern typeof (const int) ci; |
| 22 |
extern typeof (ci) ci; |
| 23 |
|
| 24 |
extern typeof_unqual (const int) i; |
| 25 |
extern typeof_unqual (ci) i; |
| 26 |
extern typeof ((const int) ci) i; |
| 27 |
extern typeof (+ci) i; |
| 28 |
extern typeof (0, ci) i; |
| 29 |
extern typeof (1 ? ci : ci) i; |
| 30 |
extern typeof (0) i; |
| 31 |
|
| 32 |
const int fci (void); |
| 33 |
extern typeof (fci ()) i; |
| 34 |
|
| 35 |
_Atomic int ai; |
| 36 |
extern typeof (_Atomic int) ai; |
| 37 |
extern typeof (_Atomic (int)) ai; |
| 38 |
extern typeof (ai) ai; |
| 39 |
|
| 40 |
extern typeof_unqual (_Atomic int) i; |
| 41 |
extern typeof_unqual (_Atomic (int)) i; |
| 42 |
extern typeof_unqual (ai) i; |
| 43 |
extern typeof (+ai) i; |
| 44 |
extern typeof ((_Atomic int) ai) i; |
| 45 |
extern typeof (0, ai) i; |
| 46 |
extern typeof (1 ? ai : ai) i; |
| 47 |
|
| 48 |
_Atomic int fai (void); |
| 49 |
extern typeof (fai ()) i; |
| 50 |
|
| 51 |
_Atomic const volatile int acvi; |
| 52 |
extern typeof (int volatile const _Atomic) acvi; |
| 53 |
extern typeof (acvi) acvi; |
| 54 |
extern const _Atomic volatile typeof (acvi) acvi; |
| 55 |
extern _Atomic volatile typeof (ci) acvi; |
| 56 |
extern _Atomic const typeof (vi) acvi; |
| 57 |
extern const typeof (ai) volatile acvi; |
| 58 |
|
| 59 |
extern typeof_unqual (acvi) i; |
| 60 |
extern typeof_unqual (typeof (acvi)) i; |
| 61 |
extern typeof_unqual (_Atomic typeof_unqual (acvi)) i; |
| 62 |
|
| 63 |
extern _Atomic typeof_unqual (acvi) ai; |
| 64 |
|
| 65 |
char c; |
| 66 |
volatile char vc; |
| 67 |
volatile char *pvc; |
| 68 |
volatile char *const cpvc; |
| 69 |
const char *pcc; |
| 70 |
const char *volatile vpcc; |
| 71 |
typeof (*vpcc) cc; |
| 72 |
|
| 73 |
extern typeof (*cpvc) vc; |
| 74 |
extern typeof_unqual (*cpvc) c; |
| 75 |
extern typeof_unqual (cpvc) pvc; |
| 76 |
extern typeof_unqual (vpcc) pcc; |
| 77 |
extern const char cc; |
| 78 |
|
| 79 |
extern typeof (++vi) i; |
| 80 |
extern typeof (++ai) i; |
| 81 |
extern typeof (--vi) i; |
| 82 |
extern typeof (--ai) i; |
| 83 |
extern typeof (vi++) i; |
| 84 |
extern typeof (ai++) i; |
| 85 |
extern typeof (vi--) i; |
| 86 |
extern typeof (ai--) i; |
| 87 |
|
| 88 |
bool b; |
| 89 |
volatile bool vb; |
| 90 |
_Atomic bool ab; |
| 91 |
extern typeof (++vb) b; |
| 92 |
extern typeof (++ab) b; |
| 93 |
extern typeof (--vb) b; |
| 94 |
extern typeof (--ab) b; |
| 95 |
extern typeof (vb++) b; |
| 96 |
extern typeof (ab++) b; |
| 97 |
extern typeof (vb--) b; |
| 98 |
extern typeof (ab--) b; |
| 99 |
|
| 100 |
extern typeof (vc = 1) c; |
| 101 |
extern typeof (vpcc = 0) pcc; |
| 102 |
extern typeof (ai *= 2) i; |
| 103 |
|
| 104 |
int s = sizeof (typeof (int (*)[++i])); |
| 105 |
|
| 106 |
void *vp; |
| 107 |
|
| 108 |
/* The non-returning property of a function is not part of the type given by |
| 109 |
ISO C typeof. */ |
| 110 |
_Noreturn void nf1 (void); |
| 111 |
[[noreturn]] void nf2 (void); |
| 112 |
void fg (void) {} |
| 113 |
typeof (&nf1) pnf1 = fg; |
| 114 |
typeof (&nf2) pnf2 = fg; |
| 115 |
extern void (*pnf1) (void); |
| 116 |
extern void (*pnf2) (void); |
| 117 |
extern typeof (nf1) *pnf1; |
| 118 |
extern typeof (nf1) *pnf2; |
| 119 |
extern typeof (nf2) *pnf1; |
| 120 |
extern typeof (nf2) *pnf2; |
| 121 |
typeof (*&nf1) fg2, fg2a, fg2b; |
| 122 |
typeof (*&nf2) fg3, fg3a, fg3b; |
| 123 |
typeof (nf1) fg4, fg4a, fg4b; |
| 124 |
typeof (nf2) fg5, fg5a, fg5b; |
| 125 |
|
| 126 |
extern void abort (void); |
| 127 |
extern void exit (int); |
| 128 |
|
| 129 |
void fg2 (void) {} |
| 130 |
_Noreturn void fg2a (void) { abort (); } |
| 131 |
[[noreturn]] void fg2b (void) { abort (); } |
| 132 |
void fg3 (void) {} |
| 133 |
_Noreturn void fg3a (void) { abort (); } |
| 134 |
[[noreturn]] void fg3b (void) { abort (); } |
| 135 |
void fg4 (void) {} |
| 136 |
_Noreturn void fg4a (void) { abort (); } |
| 137 |
[[noreturn]] void fg4b (void) { abort (); } |
| 138 |
void fg5 (void) {} |
| 139 |
_Noreturn void fg5a (void) { abort (); } |
| 140 |
[[noreturn]] void fg5b (void) { abort (); } |
| 141 |
|
| 142 |
extern int only_used_in_typeof; |
| 143 |
|
| 144 |
static int not_defined (void); |
| 145 |
|
| 146 |
typeof (i) |
| 147 |
main (typeof (*vp)) |
| 148 |
{ |
| 149 |
volatile typeof (only_used_in_typeof) ii = 2; |
| 150 |
if (ii != 2) |
| 151 |
abort (); |
| 152 |
const typeof (not_defined ()) jj = 3; |
| 153 |
if (jj != 3) |
| 154 |
abort (); |
| 155 |
unsigned int u = 1; |
| 156 |
typeof (u) u2 = 0; |
| 157 |
typeof (int (*)[++u2]) p = 0; |
| 158 |
if (u2 != 1) |
| 159 |
abort (); |
| 160 |
if (sizeof (*p) != sizeof (int)) |
| 161 |
abort (); |
| 162 |
typeof_unqual (int (*)[++u2]) q = 0; |
| 163 |
if (u2 != 2) |
| 164 |
abort (); |
| 165 |
if (sizeof (*q) != 2 * sizeof (int)) |
| 166 |
abort (); |
| 167 |
if (sizeof (*p) != sizeof (int)) |
| 168 |
abort (); |
| 169 |
typeof (++u2) u3 = 1; |
| 170 |
if (u2 != u + u3) |
| 171 |
abort (); |
| 172 |
typeof_unqual (++u2) u4 = 2; |
| 173 |
if (u2 != u4) |
| 174 |
abort (); |
| 175 |
u = sizeof (typeof (int (*)[++u2])); |
| 176 |
if (u2 != 2) |
| 177 |
abort (); |
| 178 |
u = sizeof (typeof_unqual (int (*)[++u2])); |
| 179 |
if (u2 != 2) |
| 180 |
abort (); |
| 181 |
typeof ((int (*)[++u2]) 0) q2; |
| 182 |
if (u2 != 3) |
| 183 |
abort (); |
| 184 |
typeof ((void) 0, (int (*)[++u2]) 0) q3; |
| 185 |
if (u2 != 4) |
| 186 |
abort (); |
| 187 |
typeof ((int (*)[++u2]) 0, 0) q4; |
| 188 |
if (u2 != 4) |
| 189 |
abort (); |
| 190 |
typeof_unqual ((int (*)[++u2]) 0) q5; |
| 191 |
if (u2 != 5) |
| 192 |
abort (); |
| 193 |
typeof_unqual ((void) 0, (int (*)[++u2]) 0) q6; |
| 194 |
if (u2 != 6) |
| 195 |
abort (); |
| 196 |
typeof_unqual ((int (*)[++u2]) 0, 0) q7; |
| 197 |
if (u2 != 6) |
| 198 |
abort (); |
| 199 |
int a1[6], a2[6]; |
| 200 |
int (*pa)[u2] = &a1; |
| 201 |
typeof (pa = &a2) pp; |
| 202 |
if (pa != &a2) |
| 203 |
abort (); |
| 204 |
typeof_unqual (pa = &a1) pp2; |
| 205 |
if (pa != &a1) |
| 206 |
abort (); |
| 207 |
exit (0); |
| 208 |
} |