Module Name: src Committed By: rillig Date: Sat Jan 9 22:55:36 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_116.c msg_116.exp Log Message: lint: add test for 116 "illegal pointer subtraction" To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_116.c \ src/tests/usr.bin/xlint/lint1/msg_116.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_116.c diff -u src/tests/usr.bin/xlint/lint1/msg_116.c:1.2 src/tests/usr.bin/xlint/lint1/msg_116.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_116.c:1.2 Fri Jan 8 21:25:03 2021 +++ src/tests/usr.bin/xlint/lint1/msg_116.c Sat Jan 9 22:55:36 2021 @@ -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; } Index: src/tests/usr.bin/xlint/lint1/msg_116.exp diff -u src/tests/usr.bin/xlint/lint1/msg_116.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_116.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_116.exp:1.2 Fri Jan 8 21:25:03 2021 +++ src/tests/usr.bin/xlint/lint1/msg_116.exp Sat Jan 9 22:55:36 2021 @@ -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]