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