msg_101.c revision 1.6 1 /* $NetBSD: msg_101.c,v 1.6 2021/06/30 14:11:08 rillig Exp $ */
2 # 3 "msg_101.c"
3
4 // Test for message: type '%s' does not have member '%s' [101]
5
6 struct point {
7 int x, y;
8 };
9
10 void sink(int);
11
12 void
13 test(const struct point *ptr, const struct point pt)
14 {
15 /* accessing an existing member */
16 sink(ptr->x);
17 sink(pt.x);
18
19 /* accessing a nonexistent member */
20 /* expect+1: error: type 'pointer to const struct point' does not have member 'z' [101] */
21 sink(ptr->z);
22 /* expect+1: error: type 'const struct point' does not have member 'z' [101] */
23 sink(pt.z);
24
25 /* mixed up '.' and '->' */
26 /* TODO: mention actual type in the diagnostic */
27 /* expect+1: error: left operand of '.' must be struct/union object [103] */
28 sink(ptr.x);
29 /* TODO: put actual type in 'quotes' */
30 /* expect+1: error: left operand of '->' must be pointer to struct/union not struct point [104] */
31 sink(pt->x);
32
33 /* accessing a nonexistent member via the wrong operator */
34 /* expect+1: error: type 'pointer to const struct point' does not have member 'z' [101] */
35 sink(ptr.z);
36 /* XXX: Why is the 'const' missing here, but not above? */
37 /* expect+1: error: type 'struct point' does not have member 'z' [101] */
38 sink(pt->z);
39 }
40