Module Name:    src
Committed By:   rillig
Date:           Sat Oct  9 19:18:53 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_346.c

Log Message:
tests/lint: test effective unconst cast using bsearch

Seen in usr.bin/indent/lexi.c, function lexi.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_346.c

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_346.c
diff -u src/tests/usr.bin/xlint/lint1/msg_346.c:1.4 src/tests/usr.bin/xlint/lint1/msg_346.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_346.c:1.4	Mon Aug 16 18:51:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_346.c	Sat Oct  9 19:18:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_346.c,v 1.4 2021/08/16 18:51:58 rillig Exp $	*/
+/*	$NetBSD: msg_346.c,v 1.5 2021/10/09 19:18:52 rillig Exp $	*/
 # 3 "msg_346.c"
 
 // Test for message: call to '%s' effectively discards 'const' from argument [346]
@@ -59,3 +59,30 @@ edge_cases(void)
 	/* expect+1: error: argument mismatch: 0 arg passed, 2 expected [150] */
 	take_char_ptr(strchr());
 }
+
+/*
+ * Bsearch is another standard function that effectively discards the 'const'
+ * modifier, but from the second argument, not the first.
+ */
+
+void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
+	int (*compar) (const void *, const void *));
+
+int cmp(const void *, const void *);
+
+void take_void_ptr(void *);
+void take_const_void_ptr(void *);
+
+void
+bsearch_example(void)
+{
+	const int const_arr[] = { 1 };
+	const int arr[] = { 1 };
+
+	take_const_void_ptr(bsearch("", const_arr, 4, 1, cmp));
+	take_const_void_ptr(bsearch("", arr, 4, 1, cmp));
+	take_void_ptr(bsearch("", arr, 4, 1, cmp));
+
+	/* TODO: expect+1: warning: call to 'bsearch' effectively discards 'const' from argument [346] */
+	take_void_ptr(bsearch("", const_arr, 4, 1, cmp));
+}

Reply via email to