In gcc/testsuite/: 2011-03-04 Nicola Pero <nicola.pero@meta-innovation.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / pr35635.c
blob45d10a67bd39b8991bf1cf42c944a31678358d24
1 /* PR 35635 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wconversion -Wsign-conversion" } */
5 struct unsigned_bit {
6 unsigned int x:1;
7 } unsigned_bit;
8 struct signed_bit {
9 int x:1;
10 } signed_bit;
11 int bar;
12 int bar2;
14 void func1()
16 /* The result of boolean operators fits in unsiged int:1, thus do
17 not warn. */
18 unsigned_bit.x = (bar != 0); /* { dg-bogus "conversion" } */
19 unsigned_bit.x = (bar == 0); /* { dg-bogus "conversion" } */
20 unsigned_bit.x = (bar <= 0); /* { dg-bogus "conversion" } */
21 unsigned_bit.x = (bar >= 0); /* { dg-bogus "conversion" } */
22 unsigned_bit.x = (bar < 0); /* { dg-bogus "conversion" } */
23 unsigned_bit.x = (bar > 0); /* { dg-bogus "conversion" } */
24 unsigned_bit.x = !bar; /* { dg-bogus "conversion" } */
25 unsigned_bit.x = (bar || bar2); /* { dg-bogus "conversion" } */
26 unsigned_bit.x = (bar && bar2); /* { dg-bogus "conversion" } */
28 /* Both branches of ? fit in the destination, thus do not warn. */
29 unsigned_bit.x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */
30 unsigned_bit.x = bar != 0 ? 1.0 : 0.0; /* { dg-bogus "conversion" } */
32 /* At least one branch of ? does not fit in the destination, thus
33 warn. */
34 unsigned_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */
35 unsigned_bit.x = bar != 0 ? 0 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
38 void func2()
40 signed char schar_x;
42 /* Both branches of ? fit in the destination, thus do not warn. */
43 schar_x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */
44 schar_x = bar != 0 ? 2.0 : 10; /* { dg-bogus "conversion" } */
46 /* At least one branch of ? does not fit in the destination, thus
47 warn. */
48 schar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */
49 schar_x = bar != 0 ? (signed char) 1024: -1024; /* { dg-warning "conversion" } */
54 void func3()
56 unsigned char uchar_x;
58 /* Both branches of ? fit in the destination, thus do not warn. */
59 uchar_x = bar != 0 ? 1 : 0;
60 uchar_x = bar != 0 ? 2.0 : 10;
62 /* At least one branch of ? does not fit in the destination, thus
63 warn. */
64 uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */
65 uchar_x = bar != 0
66 ? (unsigned char) 1024
67 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
70 void func4()
72 signed_bit.x = -1; /* { dg-bogus "conversion" } */
73 signed_bit.x = bar != 0 ? -1.0 : 0.0; /* { dg-bogus "conversion" } */
74 signed_bit.x = bar != 0 ? -1 : 0; /* { dg-bogus "conversion" } */
77 signed_bit.x = 1; /* { dg-warning "conversion" } */
78 signed_bit.x = (bar != 0); /* { dg-warning "conversion" } */
79 signed_bit.x = (bar == 0); /* { dg-warning "conversion" } */
80 signed_bit.x = (bar <= 0); /* { dg-warning "conversion" } */
81 signed_bit.x = (bar >= 0); /* { dg-warning "conversion" } */
82 signed_bit.x = (bar < 0); /* { dg-warning "conversion" } */
83 signed_bit.x = (bar > 0); /* { dg-warning "conversion" } */
84 signed_bit.x = !bar; /* { dg-warning "conversion" } */
85 signed_bit.x = (bar || bar2); /* { dg-warning "conversion" } */
86 signed_bit.x = (bar && bar2); /* { dg-warning "conversion" } */
87 signed_bit.x = bar != 0 ? 1 : 0; /* { dg-warning "conversion" } */
88 signed_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */