1 /* $NetBSD: msg_171.c,v 1.8 2022/06/16 16:58:36 rillig Exp $ */ 2 # 3 "msg_171.c" 3 4 // Test for message: cannot assign to '%s' from '%s' [171] 5 6 struct s { 7 int member; 8 }; 9 10 /*ARGSUSED*/ 11 void 12 example(int i, void *vp, struct s *s) 13 { 14 /* expect+1: error: cannot assign to 'int' from 'struct s' [171] */ 15 i = *s; 16 /* expect+1: error: cannot assign to 'struct s' from 'int' [171] */ 17 *s = i; 18 19 /* expect+1: error: cannot assign to 'pointer to void' from 'struct s' [171] */ 20 vp = *s; 21 /* expect+1: error: cannot assign to 'struct s' from 'pointer to void' [171] */ 22 *s = vp; 23 } 24 25 /* 26 * C99 6.5.2.5 says that a compound literal evaluates to an unnamed object 27 * with automatic storage duration, like any normal named object. It is an 28 * lvalue, which means that it is possible to take the address of the object. 29 * Seen in external/mpl/bind/dist/lib/dns/rbtdb.c, update_rrsetstats. 30 * 31 * Before init.c 1.111 from 2021-03-23, lint could not handle these nested 32 * initializations (the outer one for the variable 'p', the inner one for the 33 * compound literal) and wrongly complained about a type mismatch between 34 * 'struct point' and 'pointer to struct point'. 35 */ 36 void 37 pointer_to_compound_literal(void) 38 { 39 struct point { 40 int x; 41 int y; 42 }; 43 struct point *p = &(struct point){ 44 12, 5, 45 }; 46 47 /* 48 * A sizeof expression is another way to create nested 49 * initializations. 50 */ 51 struct point p2 = { 52 (int)sizeof(struct point){ 53 (int)sizeof(struct point){ 54 (int)sizeof(struct point){ 55 (int)sizeof(struct point){ 56 0, 57 0, 58 }, 59 0, 60 }, 61 0, 62 }, 63 0, 64 }, 65 0, 66 }; 67 } 68