FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / gcc.dg / compare2.c
blob0625eb9c3f65f10ef2637e65ff167dcb162877e3
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 /* ?: branches are constants. */
12 x > (tf?64:128); /* { dg-bogus "signed and unsigned" "case 1" } */
13 y > (tf?64:128); /* { dg-bogus "signed and unsigned" "case 2" } */
15 /* ?: branches are (recursively) constants. */
16 x > (tf?64:(tf?128:256)); /* { dg-bogus "signed and unsigned" "case 3" } */
17 y > (tf?64:(tf?128:256)); /* { dg-bogus "signed and unsigned" "case 4" } */
19 /* ?: branches are signed constants. */
20 x > (tf?64:-1); /* { dg-bogus "signed and unsigned" "case 5" } */
21 y > (tf?64:-1); /* { dg-warning "signed and unsigned" "case 6" } */
23 /* ?: branches are (recursively) signed constants. */
24 x > (tf?64:(tf?128:-1)); /* { dg-bogus "signed and unsigned" "case 7" } */
25 y > (tf?64:(tf?128:-1)); /* { dg-warning "signed and unsigned" "case 8" } */
27 /* Statement expression. */
28 x > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 9" } */
29 y > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 10" } */
31 /* Statement expression with recursive ?: . */
32 x > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 11" } */
33 y > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 12" } */
35 /* Statement expression with signed ?:. */
36 x > ({tf; tf?64:-1;}); /* { dg-bogus "signed and unsigned" "case 13" } */
37 y > ({tf; tf?64:-1;}); /* { dg-warning "signed and unsigned" "case 14" } */
39 /* Statement expression with recursive signed ?:. */
40 x > ({tf; tf?64:(tf?128:-1);}); /* { dg-bogus "signed and unsigned" "case 15" } */
41 y > ({tf; tf?64:(tf?128:-1);}); /* { dg-warning "signed and unsigned" "case 16" } */
43 /* ?: branches are constants. */
44 tf ? x : (tf?64:32); /* { dg-bogus "conditional expression" "case 17" } */
45 tf ? y : (tf?64:32); /* { dg-bogus "conditional expression" "case 18" } */
47 /* ?: branches are signed constants. */
48 tf ? x : (tf?64:-1); /* { dg-bogus "conditional expression" "case 19" } */
49 tf ? y : (tf?64:-1); /* { dg-warning "conditional expression" "case 20" } */
51 /* ?: branches are (recursively) constants. */
52 tf ? x : (tf?64:(tf?128:256)); /* { dg-bogus "conditional expression" "case 21" } */
53 tf ? y : (tf?64:(tf?128:256)); /* { dg-bogus "conditional expression" "case 22" } */
55 /* ?: branches are (recursively) signed constants. */
56 tf ? x : (tf?64:(tf?128:-1)); /* { dg-bogus "conditional expression" "case 23" } */
57 tf ? y : (tf?64:(tf?128:-1)); /* { dg-warning "conditional expression" "case 24" } */