msg_329.c revision 1.4
11.4Srillig/* $NetBSD: msg_329.c,v 1.4 2022/06/17 06:59:16 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.2Srilligunion u { 71.2Srillig int i1; 81.2Srillig int i2; 91.2Srillig void *vp; 101.2Srillig}; 111.2Srillig 121.2Srilligvoid 131.2Srilligexample(void) 141.2Srillig{ 151.2Srillig /* 161.2Srillig * A type cast to a union type is valid if the source type is any 171.2Srillig * member type of the union. Since all union members with the same 181.2Srillig * type have the same representation, the name of the union member 191.2Srillig * doesn't matter. 201.2Srillig * 211.2Srillig * XXX: could there be padding bits or other tricky details that are 221.2Srillig * settable per-member? These could make the type alone insufficient 231.2Srillig * for determining the exact representation. 241.2Srillig * 251.2Srillig * C99 6.5.4 "Cast operators" does not mention a union cast. On the 261.2Srillig * contrary, it says that the type name shall specify a scalar type. 271.2Srillig * 281.2Srillig * C11 6.5.4 "Cast operators" differs from C99 but still requires 291.2Srillig * scalar types for both the target type and the source value. 301.2Srillig * 311.2Srillig * This is a GCC extension. 321.2Srillig * See https://gcc.gnu.org/onlinedocs/gcc/Cast-to-Union.html. 331.2Srillig */ 341.2Srillig union u u_i1 = (union u)3; 351.2Srillig union u u_vp = (union u)(void *)0; 361.4Srillig /* expect+1: error: type 'pointer to char' is not a member of 'union u' [329] */ 371.4Srillig union u u_cp = (union u)(char *)0; 381.2Srillig} 39