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 test for ordered compari...



details:   https://anonhg.NetBSD.org/src/rev/9b704a25b5f5
branches:  trunk
changeset: 958716:9b704a25b5f5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 17 16:00:16 2021 +0000

description:
lint: add test for ordered comparison between incompatible types

diffstat:

 tests/usr.bin/xlint/lint1/msg_123.c   |  27 ++++++++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_123.exp |   7 ++++++-
 2 files changed, 30 insertions(+), 4 deletions(-)

diffs (46 lines):

diff -r 15d965983ed1 -r 9b704a25b5f5 tests/usr.bin/xlint/lint1/msg_123.c
--- a/tests/usr.bin/xlint/lint1/msg_123.c       Sun Jan 17 15:40:27 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_123.c       Sun Jan 17 16:00:16 2021 +0000
@@ -1,7 +1,28 @@
-/*     $NetBSD: msg_123.c,v 1.1 2021/01/02 10:22:43 rillig Exp $       */
+/*     $NetBSD: msg_123.c,v 1.2 2021/01/17 16:00:16 rillig Exp $       */
 # 3 "msg_123.c"
 
 // Test for message: illegal combination of %s (%s) and %s (%s), op %s [123]
 
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+void ok(_Bool);
+void bad(_Bool);
+
+void
+compare(_Bool b, int i, double d, const char *p)
+{
+       ok(b < b);
+       ok(b < i);
+       ok(b < d);
+       bad(b < p);             /* expect: 123 */
+       ok(i < b);
+       ok(i < i);
+       ok(i < d);
+       bad(i < p);             /* expect: 123 */
+       ok(d < b);
+       ok(d < i);
+       ok(d < d);
+       bad(d < p);             /* expect: 107 */
+       bad(p < b);             /* expect: 123 */
+       bad(p < i);             /* expect: 123 */
+       bad(p < d);             /* expect: 107 */
+       ok(p < p);
+}
diff -r 15d965983ed1 -r 9b704a25b5f5 tests/usr.bin/xlint/lint1/msg_123.exp
--- a/tests/usr.bin/xlint/lint1/msg_123.exp     Sun Jan 17 15:40:27 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_123.exp     Sun Jan 17 16:00:16 2021 +0000
@@ -1,1 +1,6 @@
-msg_123.c(6): syntax error ':' [249]
+msg_123.c(15): warning: illegal combination of integer (_Bool) and pointer (pointer to const char), op < [123]
+msg_123.c(19): warning: illegal combination of integer (int) and pointer (pointer to const char), op < [123]
+msg_123.c(23): operands of '<' have incompatible types (double != pointer) [107]
+msg_123.c(24): warning: illegal combination of pointer (pointer to const char) and integer (_Bool), op < [123]
+msg_123.c(25): warning: illegal combination of pointer (pointer to const char) and integer (int), op < [123]
+msg_123.c(26): operands of '<' have incompatible types (pointer != double) [107]



Home | Main Index | Thread Index | Old Index