Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/xlint/lint1 lint: add more test cases for stra...



details:   https://anonhg.NetBSD.org/src/rev/4a5ab7953fc0
branches:  trunk
changeset: 980312:4a5ab7953fc0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 31 11:59:56 2021 +0000

description:
lint: add more test cases for strange '==' warning 160

diffstat:

 tests/usr.bin/xlint/lint1/msg_160.c   |  30 ++++++++++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/msg_160.exp |   5 +++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diffs (53 lines):

diff -r 5f8330084691 -r 4a5ab7953fc0 tests/usr.bin/xlint/lint1/msg_160.c
--- a/tests/usr.bin/xlint/lint1/msg_160.c       Sun Jan 31 11:44:48 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_160.c       Sun Jan 31 11:59:56 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_160.c,v 1.3 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_160.c,v 1.4 2021/01/31 11:59:56 rillig Exp $       */
 # 3 "msg_160.c"
 
 // Test for message: operator '==' found where '=' was expected [160]
@@ -9,5 +9,31 @@
 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 */
+       return (a == b) == (c == d);    /* expect: 160, 160 */
 }
+
+void
+eval(_Bool);
+
+void
+unparenthesized(int a, int b, int c, _Bool z)
+{
+       /*
+        * This one might be legitimate since the second '==' has _Bool
+        * on both sides.  Parenthesizing its left-hand operand doesn't
+        * hurt though.
+        */
+       eval(a == b == z);              /* expect: 160 */
+
+       eval((a == b) == z);            /*FIXME*//* expect: 160 */
+
+       /*
+        * This one is definitely wrong.  C, unlike Python, does not chain
+        * comparison operators in the way mathematicians are used to.
+        */
+       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 */
+}
diff -r 5f8330084691 -r 4a5ab7953fc0 tests/usr.bin/xlint/lint1/msg_160.exp
--- a/tests/usr.bin/xlint/lint1/msg_160.exp     Sun Jan 31 11:44:48 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_160.exp     Sun Jan 31 11:59:56 2021 +0000
@@ -1,2 +1,7 @@
 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]



Home | Main Index | Thread Index | Old Index