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 tests/lint: test comparison of 'un...



details:   https://anonhg.NetBSD.org/src/rev/418ad6a0e05d
branches:  trunk
changeset: 985726:418ad6a0e05d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 05 16:47:24 2021 +0000

description:
tests/lint: test comparison of 'unsigned <= 0'

diffstat:

 tests/usr.bin/xlint/lint1/msg_162.c   |  46 ++++++++++++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_162.exp |   9 ++++++
 2 files changed, 54 insertions(+), 1 deletions(-)

diffs (73 lines):

diff -r 863ee9a251bc -r 418ad6a0e05d tests/usr.bin/xlint/lint1/msg_162.c
--- a/tests/usr.bin/xlint/lint1/msg_162.c       Sun Sep 05 16:36:56 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.c       Sun Sep 05 16:47:24 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_162.c,v 1.4 2021/08/28 14:45:19 rillig Exp $       */
+/*     $NetBSD: msg_162.c,v 1.5 2021/09/05 16:47:24 rillig Exp $       */
 # 3 "msg_162.c"
 
 // Test for message: comparison of %s with %s, op %s [162]
@@ -82,3 +82,47 @@
        if (uc == 256)
                return;
 }
+
+void take_bool(_Bool);
+
+void
+compare_operators(unsigned int x)
+{
+       /* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */
+       take_bool(x < -1);
+       /* expect+1: warning: comparison of unsigned int with 0, op < [162] */
+       take_bool(x < 0);
+       take_bool(x < 1);
+
+       /* expect+1: warning: comparison of unsigned int with negative constant, op <= [162] */
+       take_bool(x <= -1);
+       /*
+        * XXX: The expression 'x <= 0' is equivalent to 'x < 1', so lint
+        * should not warn about it, just as it doesn't warn about the
+        * inverted condition, which is 'x > 0'.
+        */
+       /* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
+       take_bool(x <= 0);
+       take_bool(x <= 1);
+
+       /* expect+1: warning: comparison of unsigned int with negative constant, op > [162] */
+       take_bool(x > -1);
+       take_bool(x > 0);
+       take_bool(x > 1);
+
+       /* expect+1: warning: comparison of unsigned int with negative constant, op >= [162] */
+       take_bool(x >= -1);
+       /* expect+1: warning: comparison of unsigned int with 0, op >= [162] */
+       take_bool(x >= 0);
+       take_bool(x >= 1);
+
+       /* expect+1: warning: comparison of unsigned int with negative constant, op == [162] */
+       take_bool(x == -1);
+       take_bool(x == 0);
+       take_bool(x == 1);
+
+       /* expect+1: warning: comparison of unsigned int with negative constant, op != [162] */
+       take_bool(x != -1);
+       take_bool(x != 0);
+       take_bool(x != 1);
+}
diff -r 863ee9a251bc -r 418ad6a0e05d tests/usr.bin/xlint/lint1/msg_162.exp
--- a/tests/usr.bin/xlint/lint1/msg_162.exp     Sun Sep 05 16:36:56 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.exp     Sun Sep 05 16:47:24 2021 +0000
@@ -7,3 +7,12 @@
 msg_162.c(47): warning: comparison of 0 with unsigned int, op <= [162]
 msg_162.c(51): warning: comparison of 0 with unsigned int, op >= [162]
 msg_162.c(76): warning: comparison of unsigned char with negative constant, op == [162]
+msg_162.c(92): warning: comparison of unsigned int with negative constant, op < [162]
+msg_162.c(94): warning: comparison of unsigned int with 0, op < [162]
+msg_162.c(98): warning: comparison of unsigned int with negative constant, op <= [162]
+msg_162.c(105): warning: comparison of unsigned int with 0, op <= [162]
+msg_162.c(109): warning: comparison of unsigned int with negative constant, op > [162]
+msg_162.c(114): warning: comparison of unsigned int with negative constant, op >= [162]
+msg_162.c(116): warning: comparison of unsigned int with 0, op >= [162]
+msg_162.c(120): warning: comparison of unsigned int with negative constant, op == [162]
+msg_162.c(125): warning: comparison of unsigned int with negative constant, op != [162]



Home | Main Index | Thread Index | Old Index