Module Name:    src
Committed By:   rillig
Date:           Tue Aug  3 18:03:54 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/xlint/lint1: Makefile
Added Files:
        src/tests/usr.bin/xlint/lint1: expr_cast.c expr_cast.exp

Log Message:
tests/lint: test casting a struct to another struct


To generate a diff of this commit:
cvs rdiff -u -r1.1100 -r1.1101 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.99 -r1.100 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/expr_cast.c \
    src/tests/usr.bin/xlint/lint1/expr_cast.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1100 src/distrib/sets/lists/tests/mi:1.1101
--- src/distrib/sets/lists/tests/mi:1.1100	Sun Aug  1 16:29:28 2021
+++ src/distrib/sets/lists/tests/mi	Tue Aug  3 18:03:54 2021
@@ -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

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.99 src/tests/usr.bin/xlint/lint1/Makefile:1.100
--- src/tests/usr.bin/xlint/lint1/Makefile:1.99	Sun Aug  1 16:29:28 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Tue Aug  3 18:03:54 2021
@@ -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.c
 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

Added files:

Index: src/tests/usr.bin/xlint/lint1/expr_cast.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_cast.c:1.1
--- /dev/null	Tue Aug  3 18:03:54 2021
+++ src/tests/usr.bin/xlint/lint1/expr_cast.c	Tue Aug  3 18:03:54 2021
@@ -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;
+}
Index: src/tests/usr.bin/xlint/lint1/expr_cast.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_cast.exp:1.1
--- /dev/null	Tue Aug  3 18:03:54 2021
+++ src/tests/usr.bin/xlint/lint1/expr_cast.exp	Tue Aug  3 18:03:54 2021
@@ -0,0 +1 @@
+expr_cast.c(20): warning: 'local' set but not used in function 'cast' [191]

Reply via email to