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: add test for unconst p...



details:   https://anonhg.NetBSD.org/src/rev/bf5f11eef3f3
branches:  trunk
changeset: 959884:bf5f11eef3f3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 28 01:36:46 2021 +0000

description:
tests/lint: add test for unconst pointer cast

diffstat:

 tests/usr.bin/xlint/lint1/msg_275.c   |  17 ++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_275.exp |   2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diffs (31 lines):

diff -r 5e9cafaa04b5 -r bf5f11eef3f3 tests/usr.bin/xlint/lint1/msg_275.c
--- a/tests/usr.bin/xlint/lint1/msg_275.c       Sun Feb 28 01:30:22 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_275.c       Sun Feb 28 01:36:46 2021 +0000
@@ -1,7 +1,18 @@
-/*     $NetBSD: msg_275.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_275.c,v 1.3 2021/02/28 01:36:46 rillig Exp $       */
 # 3 "msg_275.c"
 
 // Test for message: cast discards 'const' from pointer target type [275]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -h */
+
+char *
+unconst_string(const char *s)
+{
+       return (char *)s;       /* expect: 275 */
+}
+
+const char *
+const_string(char *s)
+{
+       return (const char *)s;
+}
diff -r 5e9cafaa04b5 -r bf5f11eef3f3 tests/usr.bin/xlint/lint1/msg_275.exp
--- a/tests/usr.bin/xlint/lint1/msg_275.exp     Sun Feb 28 01:30:22 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_275.exp     Sun Feb 28 01:36:46 2021 +0000
@@ -1,1 +1,1 @@
-msg_275.c(6): syntax error ':' [249]
+msg_275.c(11): warning: cast discards 'const' from type 'pointer to const char' [275]



Home | Main Index | Thread Index | Old Index