111
|
1 /* Test for a bogus warning on comparison between signed and unsigned.
|
|
2 This was inspired by code in gcc. */
|
|
3
|
|
4 /* { dg-do compile } */
|
|
5 /* { dg-options "-Wsign-compare" } */
|
|
6
|
|
7 int tf = 1;
|
|
8
|
|
9 void f(int x, unsigned int y)
|
|
10 {
|
|
11 /* ?: branches are constants. */
|
|
12 x > (tf?64:128); /* { dg-bogus "changes signedness" "case 1" } */
|
|
13 y > (tf?64:128); /* { dg-bogus "changes signedness" "case 2" } */
|
|
14
|
|
15 /* ?: branches are (recursively) constants. */
|
|
16 x > (tf?64:(tf?128:256)); /* { dg-bogus "changes signedness" "case 3" } */
|
|
17 y > (tf?64:(tf?128:256)); /* { dg-bogus "changes signedness" "case 4" } */
|
|
18
|
|
19 /* ?: branches are signed constants. */
|
|
20 x > (tf?64:-1); /* { dg-bogus "changes signedness" "case 5" } */
|
|
21 y > (tf?64:-1); /* { dg-warning "different signedness" "case 6" } */
|
|
22
|
|
23 /* ?: branches are (recursively) signed constants. */
|
|
24 x > (tf?64:(tf?128:-1)); /* { dg-bogus "changes signedness" "case 7" } */
|
|
25 y > (tf?64:(tf?128:-1)); /* { dg-warning "different signedness" "case 8" } */
|
|
26
|
|
27 /* Statement expression. */
|
|
28 x > ({tf; 64;}); /* { dg-bogus "changes signedness" "case 9" } */
|
|
29 y > ({tf; 64;}); /* { dg-bogus "changes signedness" "case 10" } */
|
|
30
|
|
31 /* Statement expression with recursive ?: . */
|
|
32 x > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "changes signedness" "case 11" } */
|
|
33 y > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "changes signedness" "case 12" } */
|
|
34
|
|
35 /* Statement expression with signed ?:. */
|
|
36 x > ({tf; tf?64:-1;}); /* { dg-bogus "changes signedness" "case 13" } */
|
|
37 y > ({tf; tf?64:-1;}); /* { dg-warning "different signedness" "case 14" } */
|
|
38
|
|
39 /* Statement expression with recursive signed ?:. */
|
|
40 x > ({tf; tf?64:(tf?128:-1);}); /* { dg-bogus "changes signedness" "case 15" } */
|
|
41 y > ({tf; tf?64:(tf?128:-1);}); /* { dg-warning "different signedness" "case 16" } */
|
|
42
|
|
43 /* ?: branches are constants. */
|
|
44 tf ? x : (tf?64:32); /* { dg-bogus "changes signedness" "case 17" } */
|
|
45 tf ? y : (tf?64:32); /* { dg-bogus "changes signedness" "case 18" } */
|
|
46
|
|
47 /* ?: branches are signed constants. */
|
|
48 tf ? x : (tf?64:-1); /* { dg-bogus "changes signedness" "case 19" } */
|
|
49 tf ? y : (tf?64:-1); /* { dg-warning "changes signedness" "case 20" } */
|
|
50
|
|
51 /* ?: branches are (recursively) constants. */
|
|
52 tf ? x : (tf?64:(tf?128:256)); /* { dg-bogus "changes signedness" "case 21" } */
|
|
53 tf ? y : (tf?64:(tf?128:256)); /* { dg-bogus "changes signedness" "case 22" } */
|
|
54
|
|
55 /* ?: branches are (recursively) signed constants. */
|
|
56 tf ? x : (tf?64:(tf?128:-1)); /* { dg-bogus "changes signedness" "case 23" } */
|
|
57 tf ? y : (tf?64:(tf?128:-1)); /* { dg-warning "changes signedness" "case 24" } */
|
|
58 }
|