Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix strange message about nested '...



details:   https://anonhg.NetBSD.org/src/rev/0c919f1c257b
branches:  trunk
changeset: 950794:0c919f1c257b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 31 12:20:00 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/msg_160.c   |  31 +++++++++++++++++++++++++------
 tests/usr.bin/xlint/lint1/msg_160.exp |   9 ++-------
 usr.bin/xlint/lint1/tree.c            |   8 +++++---
 3 files changed, 32 insertions(+), 16 deletions(-)

diffs (99 lines):

diff -r 8e8e19c15c2f -r 0c919f1c257b tests/usr.bin/xlint/lint1/msg_160.c
--- a/tests/usr.bin/xlint/lint1/msg_160.c       Sun Jan 31 11:59:56 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_160.c       Sun Jan 31 12:20:00 2021 +0000
@@ -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 @@
         */
        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 @@
        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));
 }
diff -r 8e8e19c15c2f -r 0c919f1c257b tests/usr.bin/xlint/lint1/msg_160.exp
--- a/tests/usr.bin/xlint/lint1/msg_160.exp     Sun Jan 31 11:59:56 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_160.exp     Sun Jan 31 12:20:00 2021 +0000
@@ -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]
diff -r 8e8e19c15c2f -r 0c919f1c257b usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Jan 31 11:59:56 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Jan 31 12:20:00 2021 +0000
@@ -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 @@
 
        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



Home | Main Index | Thread Index | Old Index