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 116 "illegal po...



details:   https://anonhg.NetBSD.org/src/rev/44e20b6b9539
branches:  trunk
changeset: 979764:44e20b6b9539
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 09 22:55:36 2021 +0000

description:
lint: add test for 116 "illegal pointer subtraction"

diffstat:

 tests/usr.bin/xlint/lint1/msg_116.c   |  30 +++++++++++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_116.exp |   3 ++-
 2 files changed, 29 insertions(+), 4 deletions(-)

diffs (48 lines):

diff -r ab91e3848517 -r 44e20b6b9539 tests/usr.bin/xlint/lint1/msg_116.c
--- a/tests/usr.bin/xlint/lint1/msg_116.c       Sat Jan 09 22:19:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_116.c       Sat Jan 09 22:55:36 2021 +0000
@@ -1,10 +1,34 @@
-/*     $NetBSD: msg_116.c,v 1.2 2021/01/08 21:25:03 rillig Exp $       */
+/*     $NetBSD: msg_116.c,v 1.3 2021/01/09 22:55:36 rillig Exp $       */
 # 3 "msg_116.c"
 
 // Test for message: illegal pointer subtraction [116]
 
-unsigned long
+/*
+ * Subtracting an int pointer from a double pointer does not make sense.
+ * The result cannot be reasonably defined since it is "the difference of
+ * the subscripts of the two array elements" (C99 6.5.5p9), and these two
+ * pointers cannot point to the same array.
+ */
+_Bool
 example(int *a, double *b)
 {
-       return a - b;
+       return a - b > 0;
 }
+
+/*
+ * Even though signed char and unsigned char have the same size,
+ * their pointer types are still considered incompatible.
+ *
+ * C99 6.5.5p9
+ */
+_Bool
+subtract_character_pointers(signed char *scp, unsigned char *ucp)
+{
+       return scp - ucp > 0;
+}
+
+_Bool
+subtract_const_pointer(const char *ccp, char *cp)
+{
+       return ccp - cp > 0;
+}
diff -r ab91e3848517 -r 44e20b6b9539 tests/usr.bin/xlint/lint1/msg_116.exp
--- a/tests/usr.bin/xlint/lint1/msg_116.exp     Sat Jan 09 22:19:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_116.exp     Sat Jan 09 22:55:36 2021 +0000
@@ -1,1 +1,2 @@
-msg_116.c(9): illegal pointer subtraction [116]
+msg_116.c(15): illegal pointer subtraction [116]
+msg_116.c(27): illegal pointer subtraction [116]



Home | Main Index | Thread Index | Old Index