msg_329.c revision 1.5
11.5Srillig/*	$NetBSD: msg_329.c,v 1.5 2023/07/07 19:45:22 rillig Exp $	*/
21.1Srillig# 3 "msg_329.c"
31.1Srillig
41.1Srillig// Test for message: type '%s' is not a member of '%s' [329]
51.1Srillig
61.5Srillig/* lint1-extra-flags: -X 351 */
71.5Srillig
81.2Srilligunion u {
91.2Srillig	int i1;
101.2Srillig	int i2;
111.2Srillig	void *vp;
121.2Srillig};
131.2Srillig
141.2Srilligvoid
151.2Srilligexample(void)
161.2Srillig{
171.2Srillig	/*
181.2Srillig	 * A type cast to a union type is valid if the source type is any
191.2Srillig	 * member type of the union.  Since all union members with the same
201.2Srillig	 * type have the same representation, the name of the union member
211.2Srillig	 * doesn't matter.
221.2Srillig	 *
231.2Srillig	 * XXX: could there be padding bits or other tricky details that are
241.2Srillig	 * settable per-member?  These could make the type alone insufficient
251.2Srillig	 * for determining the exact representation.
261.2Srillig	 *
271.2Srillig	 * C99 6.5.4 "Cast operators" does not mention a union cast.  On the
281.2Srillig	 * contrary, it says that the type name shall specify a scalar type.
291.2Srillig	 *
301.2Srillig	 * C11 6.5.4 "Cast operators" differs from C99 but still requires
311.2Srillig	 * scalar types for both the target type and the source value.
321.2Srillig	 *
331.2Srillig	 * This is a GCC extension.
341.2Srillig	 * See https://gcc.gnu.org/onlinedocs/gcc/Cast-to-Union.html.
351.2Srillig	 */
361.2Srillig	union u u_i1 = (union u)3;
371.2Srillig	union u u_vp = (union u)(void *)0;
381.4Srillig	/* expect+1: error: type 'pointer to char' is not a member of 'union u' [329] */
391.4Srillig	union u u_cp = (union u)(char *)0;
401.2Srillig}
41