Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src tests/lint: test casting a struct to another struct



details:   https://anonhg.NetBSD.org/src/rev/a62cd5f23fdb
branches:  trunk
changeset: 1022725:a62cd5f23fdb
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 03 18:03:54 2021 +0000

description:
tests/lint: test casting a struct to another struct

diffstat:

 distrib/sets/lists/tests/mi             |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile      |   4 +++-
 tests/usr.bin/xlint/lint1/expr_cast.c   |  33 +++++++++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/expr_cast.exp |   1 +
 4 files changed, 40 insertions(+), 2 deletions(-)

diffs (78 lines):

diff -r 8ea6302611fe -r a62cd5f23fdb distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Aug 03 17:44:58 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Aug 03 18:03:54 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1100 2021/08/01 16:29:28 rillig Exp $
+# $NetBSD: mi,v 1.1101 2021/08/03 18:03:54 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6240,6 +6240,8 @@
 ./usr/tests/usr.bin/xlint/lint1/expr_binary.exp                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_binary_trad.c             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_binary_trad.exp           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_cast.c                    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_cast.exp                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_precedence.c              tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_precedence.exp            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_range.c                   tests-usr.bin-tests     compattestfile,atf
diff -r 8ea6302611fe -r a62cd5f23fdb tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Tue Aug 03 17:44:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Tue Aug 03 18:03:54 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.99 2021/08/01 16:29:28 rillig Exp $
+# $NetBSD: Makefile,v 1.100 2021/08/03 18:03:54 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -135,6 +135,8 @@
 FILES+=                expr_binary.exp
 FILES+=                expr_binary_trad.c
 FILES+=                expr_binary_trad.exp
+FILES+=                expr_cast.c
+FILES+=                expr_cast.exp
 FILES+=                expr_precedence.c
 FILES+=                expr_precedence.exp
 FILES+=                expr_range.c
diff -r 8ea6302611fe -r a62cd5f23fdb tests/usr.bin/xlint/lint1/expr_cast.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_cast.c     Tue Aug 03 18:03:54 2021 +0000
@@ -0,0 +1,33 @@
+/*     $NetBSD: expr_cast.c,v 1.1 2021/08/03 18:03:54 rillig Exp $     */
+# 3 "expr_cast.c"
+
+/*
+ * Tests for value conversion using a cast-expression.
+ *
+ * K&R C does not mention any restrictions on the target type.
+ * C90 requires both the source type and the target type to be scalar.
+ */
+
+struct S {
+       int member;
+};
+
+struct S
+cast(void)
+{
+       struct S {
+               double incompatible;
+       } local = {
+               0.0
+       };
+       /* expect-3: warning: 'local' set but not used in function 'cast' [191] */
+       /*
+        * ^^ XXX: The variable _is_ used, but only in a semantically wrong
+        * expression.  Lint should rather warn about the invalid cast in the
+        * 'return' statement, but since all C compilers since C90 are
+        * required to detect this already, there is no point in duplicating
+        * that work.
+        */
+
+       return (struct S)local;
+}
diff -r 8ea6302611fe -r a62cd5f23fdb tests/usr.bin/xlint/lint1/expr_cast.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_cast.exp   Tue Aug 03 18:03:54 2021 +0000
@@ -0,0 +1,1 @@
+expr_cast.c(20): warning: 'local' set but not used in function 'cast' [191]



Home | Main Index | Thread Index | Old Index