annotate gcc/testsuite/c-c++-common/Wint-in-bool-context.c @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* PR c++/77434 */
kono
parents:
diff changeset
2 /* { dg-options "-Wint-in-bool-context" } */
kono
parents:
diff changeset
3 /* { dg-do compile } */
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 enum truth { yes, no, maybe };
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 int foo (int a, int b)
kono
parents:
diff changeset
8 {
kono
parents:
diff changeset
9 if (a > 0 && a <= (b == 1) ? 1 : 2) /* { dg-warning "boolean context" } */
kono
parents:
diff changeset
10 return 1;
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 if (a > 0 && a <= (b == 2) ? 1 : 1) /* { dg-bogus "boolean context" } */
kono
parents:
diff changeset
13 return 2;
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 if (a > 0 && a <= (b == 3) ? 0 : 2) /* { dg-warning "boolean context" } */
kono
parents:
diff changeset
16 return 3;
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 if (a == b ? 0 : 0) /* { dg-bogus "boolean context" } */
kono
parents:
diff changeset
19 return 4;
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 if (a == ((b ? 2|4 : 1) & 3 ? 0 : 2)) /* { dg-bogus "boolean context" } */
kono
parents:
diff changeset
22 return 5;
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 if (a ? 1 : 1+1) /* { dg-warning "boolean context" } */
kono
parents:
diff changeset
25 return 6;
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 if (b ? 1+1 : 1) /* { dg-warning "boolean context" } */
kono
parents:
diff changeset
28 return 7;
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 for (a = 0; 1 << a; a++); /* { dg-warning "boolean context" } */
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 if (yes || no || maybe) /* { dg-warning "boolean context" "" { target c++ } } */
kono
parents:
diff changeset
33 return 8;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 if (yes || no) /* { dg-bogus "boolean context" } */
kono
parents:
diff changeset
36 return 9;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 return 0;
kono
parents:
diff changeset
39 }