1 /* Test for diagnostics for implicit conversions between signed and
2 unsigned integer types.
3 C++ equivalent of gcc/testsuite/gcc.dg/Wsign-conversion.c */
6 // { dg-options "-fsigned-char -Wsign-conversion -ftrack-macro-expansion=0" }
9 void fsc (signed char sc);
10 void fuc (unsigned char uc);
11 unsigned fui (unsigned int ui);
12 void fsi (signed int ui);
43 uc = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
44 uc = x ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
45 uc = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
46 uc = x ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
47 ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
48 ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
49 ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
50 ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
51 ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
52 ui = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
53 ui = ui ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
55 fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
56 uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
57 fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
58 ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
59 fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
60 uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
61 fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
62 ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
63 fsi (0x80000000); /* { dg-warning "conversion" } */
64 si = 0x80000000; /* { dg-warning "conversion" } */
67 fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */
68 si = UINT_MAX - 1; /* { dg-warning "conversion" } */
69 fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
70 si = UINT_MAX - 1U; /* { dg-warning "conversion" } */
78 uc = (unsigned char) -1;
82 fsc (uc); /* { dg-warning "conversion" } */
83 sc = uc; /* { dg-warning "conversion" } */
84 fuc (sc); /* { dg-warning "conversion" } */
85 uc = sc; /* { dg-warning "conversion" } */
86 fsi (ui); /* { dg-warning "conversion" } */
87 si = ui; /* { dg-warning "conversion" } */
88 fui (si); /* { dg-warning "conversion" } */
89 ui = si; /* { dg-warning "conversion" } */
90 fui (sc); /* { dg-warning "conversion" } */
91 ui = sc; /* { dg-warning "conversion" } */
94 unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */