1 /* Test for diagnostics for implicit conversions between integer types
2 These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c */
4 /* { dg-do compile } */
5 /* { dg-options "-std=c99 -fsigned-char -Wconversion" } */
9 void fsc (signed char sc
);
10 void fuc (unsigned char uc
);
11 unsigned fui (unsigned int ui
);
12 void fsi (signed int ui
);
21 fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
22 uc
= -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
23 fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
24 uc
= '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
25 uc
= x
? 1U : -1; /* { dg-warning "conversion" } */
26 /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 25 } */
27 uc
= x
? SCHAR_MIN
: 1U; /* { dg-warning "conversion" } */
28 /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 27 } */
30 uc
= x
? 1 : -1; /* { dg-warning "conversion" } */
32 uc
= x
? SCHAR_MIN
: 1; /* { dg-warning "conversion" } */
36 uc
= (unsigned char) -1;
38 fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
39 ui
= -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
40 ui
= x
? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
41 ui
= x
? INT_MIN
: 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
42 ui
= ui
? SCHAR_MIN
: 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
43 ui
= 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
44 ui
= ui
+ INT_MIN
; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
45 ui
= x
? 1 : -1; /* { dg-warning "conversion" } */
46 ui
= ui
? SCHAR_MIN
: 1; /* { dg-warning "conversion" } */
51 fsc (uc
); /* { dg-warning "conversion" } */
52 sc
= uc
; /* { dg-warning "conversion" } */
53 fuc (sc
); /* { dg-warning "conversion" } */
54 uc
= sc
; /* { dg-warning "conversion" } */
55 fsi (ui
); /* { dg-warning "conversion" } */
56 si
= ui
; /* { dg-warning "conversion" } */
57 fui (si
); /* { dg-warning "conversion" } */
58 ui
= si
; /* { dg-warning "conversion" } */
59 fui (sc
); /* { dg-warning "conversion" } */
60 ui
= sc
; /* { dg-warning "conversion" } */
62 fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
63 ui
= '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
77 fsi (UINT_MAX
- 1); /* { dg-warning "conversion" } */
78 si
= UINT_MAX
- 1; /* { dg-warning "conversion" } */
79 fsi (UINT_MAX
- 1U); /* { dg-warning "conversion" } */
80 si
= UINT_MAX
- 1U; /* { dg-warning "conversion" } */
88 fsi (0x80000000); /* { dg-warning "conversion" } */
89 si
= 0x80000000; /* { dg-warning "conversion" } */
93 unsigned fui (unsigned a
) { return a
+ -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */