blob: 7b12ad9f561bb9e9e65183023861316f1b7b1bef [file] [log] [blame]
Egor Pasko167ac2b2010-05-18 12:26:511/* Test diagnostics for bad or doubtful casts. Test with no special
2 options. */
3/* Origin: Joseph Myers <[email protected]> */
4/* { dg-do compile } */
5/* { dg-options "-std=gnu99" } */
6
7struct s { int a; } sv;
8union u { int a; } uv;
9int i;
10long l;
11char c;
12void *p;
13float fv;
14
15void
16f (void)
17{
18 (int []) p; /* { dg-error "cast specifies array type" } */
19 (int ()) p; /* { dg-error "cast specifies function type" } */
20 (struct s) sv;
21 (union u) uv;
22 (struct s) i; /* { dg-error "conversion to non-scalar type requested" } */
23 (union u) i;
24 (union u) l; /* { dg-error "cast to union type from type not present in union" } */
25 (int) sv; /* { dg-error "aggregate value used where an integer was expected" } */
26 (int) uv; /* { dg-error "aggregate value used where an integer was expected" } */
27 (float) sv; /* { dg-error "aggregate value used where a float was expected" } */
28 (float) uv; /* { dg-error "aggregate value used where a float was expected" } */
29 (_Complex double) sv; /* { dg-error "aggregate value used where a complex was expected" } */
30 (_Complex double) uv; /* { dg-error "aggregate value used where a complex was expected" } */
31 (void *) sv; /* { dg-error "cannot convert to a pointer type" } */
32 (void *) uv; /* { dg-error "cannot convert to a pointer type" } */
33 (_Bool) sv; /* { dg-error "used struct type value where scalar is required" } */
34 (_Bool) uv; /* { dg-error "used union type value where scalar is required" } */
35 (void) sv;
36 (const void) uv;
37 (void *) c; /* { dg-warning "cast to pointer from integer of different size" } */
38 (void *) (char) 1;
39 (char) p; /* { dg-warning "cast from pointer to integer of different size" } */
40 (char) (void *) 1; /* { dg-warning "cast from pointer to integer of different size" } */
41}