PR tree-optimization/67955
[official-gcc.git] / gcc / testsuite / c-c++-common / Wtautological-compare-1.c
blob71ba4f80484f4f9bd41d33c22d24db8b249554d4
1 /* PR c++/66555 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wtautological-compare" } */
5 #define X 5
6 #define Y 5
7 #define A a
8 enum { U };
10 void
11 fn1 (int a, int *p)
13 if (a > a); /* { dg-warning "self-comparison always evaluates to false" } */
14 if (a < a); /* { dg-warning "self-comparison always evaluates to false" } */
15 if (a >= a); /* { dg-warning "self-comparison always evaluates to true" } */
16 if (a <= a); /* { dg-warning "self-comparison always evaluates to true" } */
17 if (a == a); /* { dg-warning "self-comparison always evaluates to true" } */
18 if (a != a); /* { dg-warning "self-comparison always evaluates to false" } */
19 if (A == A); /* { dg-warning "self-comparison always evaluates to true" } */
20 if ((unsigned) a != (unsigned) a);
21 if ((a + 1) <= (a + 1)); /* { dg-warning "self-comparison always evaluates to true" } */
22 if (1 ? a == a : 0); /* { dg-warning "self-comparison always evaluates to true" } */
23 if (fn1 == fn1); /* { dg-warning "self-comparison always evaluates to true" } */
24 if (*p == *p); /* { dg-warning "self-comparison always evaluates to true" } */
26 volatile int v = 5;
27 if (v == v);
28 if (v != v);
31 void
32 fn2 (int a)
34 if (sizeof (int) >= 4);
35 if (sizeof (char) != 1);
36 if (sizeof (long) != sizeof (long long));
37 if (0 < sizeof (short));
38 if (5 != 5);
39 if (X > 5);
40 if (X == X);
41 if (3 + 4 == 6 + 1);
42 if ((unsigned) a != (unsigned long) a);
43 if (U == U);
44 if (U > 0);
47 void
48 fn3 (int i, int j)
50 static int a[16];
51 static int b[8][8];
53 if (a[5] == a[5]);
54 if (a[X] != a[Y]);
55 if (a[X] != a[X]);
56 if (a[i] == a[i]); /* { dg-warning "self-comparison always evaluates to true" } */
57 if (b[5][5] == b[5][5]);
58 if (b[X][Y] >= b[Y][X]);
59 if (b[X][X] == b[Y][Y]);
60 if (b[i][j] != b[i][j]); /* { dg-warning "self-comparison always evaluates to false" } */
61 if (b[i][Y] < b[i][X]);
62 if (b[X][j] < b[X][j]);
63 if ((a[i] + 4) == (4 + a[i])); /* { dg-warning "self-comparison always evaluates to true" } */
66 int
67 fn4 (int x, int y)
69 return x > x ? 1 : 0; /* { dg-warning "self-comparison always evaluates to false" } */