2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / compare3.c
blobeda3faf2754a7b1a4041e6edf0ff5c05136f4de6
1 /* Test for a bogus warning on comparison between signed and unsigned.
2 This was inspired by code in gcc. */
4 /* { dg-do compile } */
5 /* { dg-options "-Wsign-compare" } */
7 int tf = 1;
9 void f(int x, unsigned int y)
11 /* Test comparing conditional expressions containing truth values.
12 This can occur explicitly, or e.g. when (foo?2:(bar?1:0)) is
13 optimized into (foo?2:(bar!=0)). */
14 x > (tf?64:(tf!=x)); /* { dg-bogus "signed and unsigned" "case 1" } */
15 y > (tf?64:(tf!=x)); /* { dg-bogus "signed and unsigned" "case 2" } */
16 x > (tf?(tf!=x):64); /* { dg-bogus "signed and unsigned" "case 3" } */
17 y > (tf?(tf!=x):64); /* { dg-bogus "signed and unsigned" "case 4" } */
19 x > (tf?64:(tf==x)); /* { dg-bogus "signed and unsigned" "case 5" } */
20 y > (tf?64:(tf==x)); /* { dg-bogus "signed and unsigned" "case 6" } */
21 x > (tf?(tf==x):64); /* { dg-bogus "signed and unsigned" "case 7" } */
22 y > (tf?(tf==x):64); /* { dg-bogus "signed and unsigned" "case 8" } */
24 x > (tf?64:(tf>x)); /* { dg-bogus "signed and unsigned" "case 9" } */
25 y > (tf?64:(tf>x)); /* { dg-bogus "signed and unsigned" "case 10" } */
26 x > (tf?(tf>x):64); /* { dg-bogus "signed and unsigned" "case 11" } */
27 y > (tf?(tf>x):64); /* { dg-bogus "signed and unsigned" "case 12" } */
29 x < (tf?64:(tf<x)); /* { dg-bogus "signed and unsigned" "case 13" } */
30 y < (tf?64:(tf<x)); /* { dg-bogus "signed and unsigned" "case 14" } */
31 x < (tf?(tf<x):64); /* { dg-bogus "signed and unsigned" "case 15" } */
32 y < (tf?(tf<x):64); /* { dg-bogus "signed and unsigned" "case 16" } */
34 x > (tf?64:(tf>=x)); /* { dg-bogus "signed and unsigned" "case 17" } */
35 y > (tf?64:(tf>=x)); /* { dg-bogus "signed and unsigned" "case 18" } */
36 x > (tf?(tf>=x):64); /* { dg-bogus "signed and unsigned" "case 19" } */
37 y > (tf?(tf>=x):64); /* { dg-bogus "signed and unsigned" "case 20" } */
39 x > (tf?64:(tf<=x)); /* { dg-bogus "signed and unsigned" "case 21" } */
40 y > (tf?64:(tf<=x)); /* { dg-bogus "signed and unsigned" "case 22" } */
41 x > (tf?(tf<=x):64); /* { dg-bogus "signed and unsigned" "case 23" } */
42 y > (tf?(tf<=x):64); /* { dg-bogus "signed and unsigned" "case 24" } */
44 x > (tf?64:(tf&&x)); /* { dg-bogus "signed and unsigned" "case 25" } */
45 y > (tf?64:(tf&&x)); /* { dg-bogus "signed and unsigned" "case 26" } */
46 x > (tf?(tf&&x):64); /* { dg-bogus "signed and unsigned" "case 27" } */
47 y > (tf?(tf&&x):64); /* { dg-bogus "signed and unsigned" "case 28" } */
49 x > (tf?64:(tf||x)); /* { dg-bogus "signed and unsigned" "case 29" } */
50 y > (tf?64:(tf||x)); /* { dg-bogus "signed and unsigned" "case 30" } */
51 x > (tf?(tf||x):64); /* { dg-bogus "signed and unsigned" "case 31" } */
52 y > (tf?(tf||x):64); /* { dg-bogus "signed and unsigned" "case 32" } */
54 x > (tf?64:(!tf)); /* { dg-bogus "signed and unsigned" "case 33" } */
55 y > (tf?64:(!tf)); /* { dg-bogus "signed and unsigned" "case 34" } */
56 x > (tf?(!tf):64); /* { dg-bogus "signed and unsigned" "case 35" } */
57 y > (tf?(!tf):64); /* { dg-bogus "signed and unsigned" "case 36" } */