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 effective unconst...
details: https://anonhg.NetBSD.org/src/rev/b425664fd655
branches: trunk
changeset: 989007:b425664fd655
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Oct 09 19:18:52 2021 +0000
description:
tests/lint: test effective unconst cast using bsearch
Seen in usr.bin/indent/lexi.c, function lexi.
diffstat:
tests/usr.bin/xlint/lint1/msg_346.c | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diffs (40 lines):
diff -r 3fd5a1040955 -r b425664fd655 tests/usr.bin/xlint/lint1/msg_346.c
--- a/tests/usr.bin/xlint/lint1/msg_346.c Sat Oct 09 14:22:42 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_346.c Sat Oct 09 19:18:52 2021 +0000
@@ -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 @@
/* 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));
+}
Home |
Main Index |
Thread Index |
Old Index