File: cast-3.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (41 lines) | stat: -rw-r--r-- 2,006 bytes parent folder | download | duplicates (2)
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
/* Test diagnostics for bad or doubtful casts.  Test with
   -pedantic-errors.  */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -pedantic-errors" } */

struct s { int a; } sv;
union u { int a; } uv;
int i;
long l;
char c;
void *p;
float fv;

void
f (void)
{
  (int []) p; /* { dg-error "cast specifies array type" } */
  (int ()) p; /* { dg-error "cast specifies function type" } */
  (struct s) sv; /* { dg-error "ISO C forbids casting nonscalar to the same type" } */
  (union u) uv; /* { dg-error "ISO C forbids casting nonscalar to the same type" } */
  (struct s) i; /* { dg-error "conversion to non-scalar type requested" } */
  (union u) i; /* { dg-error "ISO C forbids casts to union type" } */
  (union u) l; /* { dg-error "cast to union type from type not present in union" } */
  (int) sv; /* { dg-error "aggregate value used where an integer was expected" } */
  (int) uv; /* { dg-error "aggregate value used where an integer was expected" } */
  (float) sv; /* { dg-error "aggregate value used where a floating-point was expected" } */
  (float) uv; /* { dg-error "aggregate value used where a floating-point was expected" } */
  (_Complex double) sv; /* { dg-error "aggregate value used where a complex was expected" } */
  (_Complex double) uv; /* { dg-error "aggregate value used where a complex was expected" } */
  (void *) sv; /* { dg-error "cannot convert to a pointer type" } */
  (void *) uv; /* { dg-error "cannot convert to a pointer type" } */
  (_Bool) sv; /* { dg-error "used struct type value where scalar is required" } */
  (_Bool) uv; /* { dg-error "used union type value where scalar is required" } */
  (void) sv;
  (const void) uv;
  (void *) c; /* { dg-warning "cast to pointer from integer of different size" } */
  (void *) (char) 1;
  (char) p; /* { dg-warning "cast from pointer to integer of different size" } */
  (char) (void *) 1; /* { dg-warning "cast from pointer to integer of different size" } */
}