2007-02-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / Wconversion-integer.c
blob515aba30dbf47114158466b97fc314ad667c7819
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" } */
7 #include <limits.h>
9 void fsc (signed char sc);
10 void fuc (unsigned char uc);
11 unsigned fui (unsigned int ui);
12 void fsi (signed int ui);
14 void h (int x)
16 unsigned int ui = 3;
17 int si = 3;
18 unsigned char uc = 3;
19 signed char sc = 3;
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" } */
34 fuc ('A');
35 uc = 'A';
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" } */
48 ui = -1 * (1 * -1);
49 ui = (unsigned) -1;
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" } */
65 fsi (si);
66 fui (ui);
67 fsi (uc);
68 si = uc;
69 fui (uc);
70 ui = uc;
71 fui ('A');
72 ui = 'A';
73 fsi ('A');
74 si = 'A';
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" } */
81 fsi (UINT_MAX/3U);
82 si = UINT_MAX/3U;
83 fsi (UINT_MAX/3);
84 si = UINT_MAX/3;
85 fui (UINT_MAX - 1);
86 ui = UINT_MAX - 1;
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" } */