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 lint: add test for message 329, un...
details: https://anonhg.NetBSD.org/src/rev/edbb7793866c
branches: trunk
changeset: 950316:edbb7793866c
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 24 17:44:37 2021 +0000
description:
lint: add test for message 329, union cast with incompatible type
diffstat:
tests/usr.bin/xlint/lint1/msg_329.c | 39 ++++++++++++++++++++++++++++++++--
tests/usr.bin/xlint/lint1/msg_329.exp | 2 +-
2 files changed, 37 insertions(+), 4 deletions(-)
diffs (53 lines):
diff -r 3ee3afbebb45 -r edbb7793866c tests/usr.bin/xlint/lint1/msg_329.c
--- a/tests/usr.bin/xlint/lint1/msg_329.c Sun Jan 24 17:44:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_329.c Sun Jan 24 17:44:37 2021 +0000
@@ -1,7 +1,40 @@
-/* $NetBSD: msg_329.c,v 1.1 2021/01/02 10:22:44 rillig Exp $ */
+/* $NetBSD: msg_329.c,v 1.2 2021/01/24 17:44:37 rillig Exp $ */
# 3 "msg_329.c"
// Test for message: type '%s' is not a member of '%s' [329]
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+union u {
+ int i1;
+ int i2;
+ void *vp;
+};
+
+void
+example(void)
+{
+ /*
+ * A type cast to a union type is valid if the source type is any
+ * member type of the union. Since all union members with the same
+ * type have the same representation, the name of the union member
+ * doesn't matter.
+ *
+ * XXX: could there be padding bits or other tricky details that are
+ * settable per-member? These could make the type alone insufficient
+ * for determining the exact representation.
+ *
+ * C99 6.5.4 "Cast operators" does not mention a union cast. On the
+ * contrary, it says that the type name shall specify a scalar type.
+ *
+ * C11 6.5.4 "Cast operators" differs from C99 but still requires
+ * scalar types for both the target type and the source value.
+ *
+ * This is a GCC extension.
+ * See https://gcc.gnu.org/onlinedocs/gcc/Cast-to-Union.html.
+ *
+ * FIXME: lint says in message 328 that "union cast is a C9X feature",
+ * but that is wrong. It is a GCC feature.
+ */
+ union u u_i1 = (union u)3;
+ union u u_vp = (union u)(void *)0;
+ union u u_cp = (union u)(char *)0; /* expect: 329 */
+}
diff -r 3ee3afbebb45 -r edbb7793866c tests/usr.bin/xlint/lint1/msg_329.exp
--- a/tests/usr.bin/xlint/lint1/msg_329.exp Sun Jan 24 17:44:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_329.exp Sun Jan 24 17:44:37 2021 +0000
@@ -1,1 +1,1 @@
-msg_329.c(6): syntax error ':' [249]
+msg_329.c(39): type 'pointer to char' is not a member of 'union u' [329]
Home |
Main Index |
Thread Index |
Old Index