1 /* $NetBSD: msg_329.c,v 1.2 2021/01/24 17:44:37 rillig Exp $ */ 2 # 3 "msg_329.c" 3 4 // Test for message: type '%s' is not a member of '%s' [329] 5 6 union u { 7 int i1; 8 int i2; 9 void *vp; 10 }; 11 12 void 13 example(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 } 41