msg_160.c revision 1.5 1 1.5 rillig /* $NetBSD: msg_160.c,v 1.5 2021/01/31 12:20:00 rillig Exp $ */
2 1.1 rillig # 3 "msg_160.c"
3 1.1 rillig
4 1.1 rillig // Test for message: operator '==' found where '=' was expected [160]
5 1.1 rillig
6 1.2 rillig /* lint1-extra-flags: -h */
7 1.2 rillig
8 1.2 rillig _Bool
9 1.2 rillig both_equal_or_unequal(int a, int b, int c, int d)
10 1.2 rillig {
11 1.5 rillig /*
12 1.5 rillig * Before tree.c 1.201 from 2021-01-31, lint warned about each of
13 1.5 rillig * the '==' subexpressions even though there is nothing surprising
14 1.5 rillig * about them.
15 1.5 rillig */
16 1.5 rillig return (a == b) == (c == d);
17 1.4 rillig }
18 1.4 rillig
19 1.4 rillig void
20 1.4 rillig eval(_Bool);
21 1.4 rillig
22 1.4 rillig void
23 1.4 rillig unparenthesized(int a, int b, int c, _Bool z)
24 1.4 rillig {
25 1.4 rillig /*
26 1.4 rillig * This one might be legitimate since the second '==' has _Bool
27 1.4 rillig * on both sides. Parenthesizing its left-hand operand doesn't
28 1.4 rillig * hurt though.
29 1.4 rillig */
30 1.4 rillig eval(a == b == z); /* expect: 160 */
31 1.4 rillig
32 1.5 rillig /*
33 1.5 rillig * Before tree.c 1.201 from 2021-01-31, lint warned about the
34 1.5 rillig * parenthesized '==' subexpression even though there is nothing
35 1.5 rillig * surprising about it.
36 1.5 rillig */
37 1.5 rillig eval((a == b) == z);
38 1.4 rillig
39 1.4 rillig /*
40 1.4 rillig * This one is definitely wrong. C, unlike Python, does not chain
41 1.4 rillig * comparison operators in the way mathematicians are used to.
42 1.4 rillig */
43 1.4 rillig eval(a == b == c); /* expect: 160 */
44 1.4 rillig
45 1.4 rillig /* Parenthesizing one of the operands makes it obvious enough. */
46 1.5 rillig /*
47 1.5 rillig * Before tree.c 1.201 from 2021-01-31, lint warned about the
48 1.5 rillig * parenthesized '==' subexpression even though there is nothing
49 1.5 rillig * surprising about it.
50 1.5 rillig */
51 1.5 rillig eval((a == b) == c);
52 1.5 rillig /*
53 1.5 rillig * Before tree.c 1.201 from 2021-01-31, lint warned about the
54 1.5 rillig * parenthesized '==' subexpression even though there is nothing
55 1.5 rillig * surprising about it.
56 1.5 rillig */
57 1.5 rillig eval(a == (b == c));
58 1.2 rillig }
59