Module Name: src
Committed By: rillig
Date: Sun Jan 31 12:20:01 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_160.c msg_160.exp
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: fix strange message about nested '==' operators
If one of the nested subexpressions is parenthesized, the author
probably knew how these expressions are evaluated. Therefore don't warn
in such a situation.
Maybe the original author once made a typo and tried to initialize
variables but instead compared them, like this:
int a, b, c;
a == b == c;
This would explain the text of the message, which still sounds strange.
At least it doesn't show up as often anymore.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_160.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_160.exp
cvs rdiff -u -r1.200 -r1.201 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/msg_160.c
diff -u src/tests/usr.bin/xlint/lint1/msg_160.c:1.4 src/tests/usr.bin/xlint/lint1/msg_160.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_160.c:1.4 Sun Jan 31 11:59:56 2021
+++ src/tests/usr.bin/xlint/lint1/msg_160.c Sun Jan 31 12:20:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_160.c,v 1.4 2021/01/31 11:59:56 rillig Exp $ */
+/* $NetBSD: msg_160.c,v 1.5 2021/01/31 12:20:00 rillig Exp $ */
# 3 "msg_160.c"
// Test for message: operator '==' found where '=' was expected [160]
@@ -8,8 +8,12 @@
_Bool
both_equal_or_unequal(int a, int b, int c, int d)
{
- /* XXX: Why shouldn't this be legitimate? */
- return (a == b) == (c == d); /* expect: 160, 160 */
+ /*
+ * Before tree.c 1.201 from 2021-01-31, lint warned about each of
+ * the '==' subexpressions even though there is nothing surprising
+ * about them.
+ */
+ return (a == b) == (c == d);
}
void
@@ -25,7 +29,12 @@ unparenthesized(int a, int b, int c, _Bo
*/
eval(a == b == z); /* expect: 160 */
- eval((a == b) == z); /*FIXME*//* expect: 160 */
+ /*
+ * Before tree.c 1.201 from 2021-01-31, lint warned about the
+ * parenthesized '==' subexpression even though there is nothing
+ * surprising about it.
+ */
+ eval((a == b) == z);
/*
* This one is definitely wrong. C, unlike Python, does not chain
@@ -34,6 +43,16 @@ unparenthesized(int a, int b, int c, _Bo
eval(a == b == c); /* expect: 160 */
/* Parenthesizing one of the operands makes it obvious enough. */
- eval((a == b) == c); /*FIXME*//* expect: 160 */
- eval(a == (b == c)); /*FIXME*//* expect: 160 */
+ /*
+ * Before tree.c 1.201 from 2021-01-31, lint warned about the
+ * parenthesized '==' subexpression even though there is nothing
+ * surprising about it.
+ */
+ eval((a == b) == c);
+ /*
+ * Before tree.c 1.201 from 2021-01-31, lint warned about the
+ * parenthesized '==' subexpression even though there is nothing
+ * surprising about it.
+ */
+ eval(a == (b == c));
}
Index: src/tests/usr.bin/xlint/lint1/msg_160.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_160.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_160.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_160.exp:1.3 Sun Jan 31 11:59:56 2021
+++ src/tests/usr.bin/xlint/lint1/msg_160.exp Sun Jan 31 12:20:00 2021
@@ -1,7 +1,2 @@
-msg_160.c(12): warning: operator '==' found where '=' was expected [160]
-msg_160.c(12): warning: operator '==' found where '=' was expected [160]
-msg_160.c(26): warning: operator '==' found where '=' was expected [160]
-msg_160.c(28): warning: operator '==' found where '=' was expected [160]
-msg_160.c(34): warning: operator '==' found where '=' was expected [160]
-msg_160.c(37): warning: operator '==' found where '=' was expected [160]
-msg_160.c(38): warning: operator '==' found where '=' was expected [160]
+msg_160.c(30): warning: operator '==' found where '=' was expected [160]
+msg_160.c(43): warning: operator '==' found where '=' was expected [160]
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.200 src/usr.bin/xlint/lint1/tree.c:1.201
--- src/usr.bin/xlint/lint1/tree.c:1.200 Sun Jan 31 11:44:48 2021
+++ src/usr.bin/xlint/lint1/tree.c Sun Jan 31 12:20:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.200 2021/01/31 11:44:48 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.201 2021/01/31 12:20:00 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.200 2021/01/31 11:44:48 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.201 2021/01/31 12:20:00 rillig Exp $");
#endif
#include <float.h>
@@ -4006,7 +4006,9 @@ check_expr_misc(const tnode_t *tn, bool
bool cvctx = mp->m_left_value_context;
bool ctctx = mp->m_left_test_context;
- bool eq = mp->m_warn_if_operand_eq;
+ bool eq = mp->m_warn_if_operand_eq &&
+ !ln->tn_parenthesized &&
+ rn != NULL && !rn->tn_parenthesized;
/*
* values of operands of ':' are not used if the type of at least