Sun Jan 24 17:44:37 2021 UTC ()
lint: add test for message 329, union cast with incompatible type


(rillig)
diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_329.c
diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_329.exp

cvs diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_329.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/msg_329.c 2021/01/02 10:22:44 1.1
+++ src/tests/usr.bin/xlint/lint1/msg_329.c 2021/01/24 17:44:37 1.2
@@ -1,7 +1,40 @@ @@ -1,7 +1,40 @@
1/* $NetBSD: msg_329.c,v 1.1 2021/01/02 10:22:44 rillig Exp $ */ 1/* $NetBSD: msg_329.c,v 1.2 2021/01/24 17:44:37 rillig Exp $ */
2# 3 "msg_329.c" 2# 3 "msg_329.c"
3 3
4// Test for message: type '%s' is not a member of '%s' [329] 4// Test for message: type '%s' is not a member of '%s' [329]
5 5
6TODO: "Add example code that triggers the above message." 6union u {
7TODO: "Add example code that almost triggers the above message." 7 int i1;
 8 int i2;
 9 void *vp;
 10};
 11
 12void
 13example(void)
 14{
 15 /*
 16 * A type cast to a union type is valid if the source type is any
 17 * member type of the union. Since all union members with the same
 18 * type have the same representation, the name of the union member
 19 * doesn't matter.
 20 *
 21 * XXX: could there be padding bits or other tricky details that are
 22 * settable per-member? These could make the type alone insufficient
 23 * for determining the exact representation.
 24 *
 25 * C99 6.5.4 "Cast operators" does not mention a union cast. On the
 26 * contrary, it says that the type name shall specify a scalar type.
 27 *
 28 * C11 6.5.4 "Cast operators" differs from C99 but still requires
 29 * scalar types for both the target type and the source value.
 30 *
 31 * This is a GCC extension.
 32 * See https://gcc.gnu.org/onlinedocs/gcc/Cast-to-Union.html.
 33 *
 34 * FIXME: lint says in message 328 that "union cast is a C9X feature",
 35 * but that is wrong. It is a GCC feature.
 36 */
 37 union u u_i1 = (union u)3;
 38 union u u_vp = (union u)(void *)0;
 39 union u u_cp = (union u)(char *)0; /* expect: 329 */
 40}

cvs diff -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/Attic/msg_329.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/msg_329.exp 2021/01/02 10:22:44 1.1
+++ src/tests/usr.bin/xlint/lint1/Attic/msg_329.exp 2021/01/24 17:44:37 1.2