| 1 |
/* Test GNU extensions __typeof__ and __typeof_unqual__. Invalid code. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-std=c11 -pedantic-errors" } */ |
| 4 |
|
| 5 |
struct s { int i : 2; } x; |
| 6 |
union u { unsigned int j : 1; } y; |
| 7 |
|
| 8 |
__typeof__ (x.i) j; /* { dg-error "applied to a bit-field" } */ |
| 9 |
__typeof_unqual__ (x.i) j2; /* { dg-error "applied to a bit-field" } */ |
| 10 |
__typeof (y.j) j3; /* { dg-error "applied to a bit-field" } */ |
| 11 |
__typeof_unqual (y.j) j4; /* { dg-error "applied to a bit-field" } */ |
| 12 |
|
| 13 |
static int ok (void); |
| 14 |
static int also_ok (void); |
| 15 |
static int not_defined (void); /* { dg-error "used but never defined" } */ |
| 16 |
static int also_not_defined (void); /* { dg-error "used but never defined" } */ |
| 17 |
|
| 18 |
_Noreturn void nf1 (void); |
| 19 |
__attribute__((noreturn)) void nf2 (void); |
| 20 |
void fg (void) {} |
| 21 |
__typeof__ (&nf1) pnf1 = fg; /* { dg-error "qualified function pointer from unqualified" } */ |
| 22 |
__typeof (&nf2) pnf2 = fg; /* { dg-error "qualified function pointer from unqualified" } */ |
| 23 |
extern void (*pnf1) (void); /* { dg-error "conflicting types for" } */ |
| 24 |
extern void (*pnf2) (void); /* { dg-error "conflicting types for" } */ |
| 25 |
extern __typeof (nf1) *pnf1; /* { dg-error "conflicting types for" } */ |
| 26 |
extern __typeof (nf1) *pnf2; /* { dg-error "conflicting types for" } */ |
| 27 |
extern __typeof__ (nf2) *pnf1; /* { dg-error "conflicting types for" } */ |
| 28 |
extern __typeof__ (nf2) *pnf2; /* { dg-error "conflicting types for" } */ |
| 29 |
__typeof (*&nf1) fg2, fg2a, fg2b; /* { dg-error "ISO C forbids qualified function types" } */ |
| 30 |
__typeof__ (*&nf2) fg3, fg3a, fg3b; /* { dg-error "ISO C forbids qualified function types" } */ |
| 31 |
__typeof (nf1) fg4, fg4a, fg4b; |
| 32 |
__typeof__ (nf2) fg5, fg5a, fg5b; |
| 33 |
|
| 34 |
extern void abort (void); |
| 35 |
|
| 36 |
void fg2 (void) {} /* { dg-error "conflicting type qualifiers for" } */ |
| 37 |
_Noreturn void fg2a (void) { abort (); } /* { dg-error "conflicting type qualifiers for" } */ |
| 38 |
__attribute__((noreturn)) void fg2b (void) { abort (); } /* { dg-error "conflicting type qualifiers for" } */ |
| 39 |
void fg3 (void) {} /* { dg-error "conflicting type qualifiers for" } */ |
| 40 |
_Noreturn void fg3a (void) { abort (); } /* { dg-error "conflicting type qualifiers for" } */ |
| 41 |
__attribute__((noreturn)) void fg3b (void) { abort (); } /* { dg-error "conflicting type qualifiers for" } */ |
| 42 |
void fg4 (void) {} |
| 43 |
_Noreturn void fg4a (void) { abort (); } |
| 44 |
__attribute__((noreturn)) void fg4b (void) { abort (); } |
| 45 |
void fg5 (void) {} |
| 46 |
_Noreturn void fg5a (void) { abort (); } |
| 47 |
__attribute__((noreturn)) void fg5b (void) { abort (); } |
| 48 |
|
| 49 |
void |
| 50 |
f (void) |
| 51 |
{ |
| 52 |
__typeof__ (ok ()) x = 2; |
| 53 |
__typeof_unqual (also_ok ()) y = 2; |
| 54 |
int a[2]; |
| 55 |
int (*p)[x] = &a; |
| 56 |
__typeof (p + not_defined ()) q; |
| 57 |
__typeof_unqual__ (p + also_not_defined ()) q2; |
| 58 |
} |