msg_102.c revision 1.5
1/* $NetBSD: msg_102.c,v 1.5 2023/06/30 09:21:52 rillig Exp $ */ 2# 3 "msg_102.c" 3 4// Test for message: illegal use of member '%s' [102] 5 6// Anonymous members are defined in C11 6.7.2.1p2. 7 8struct unrelated { 9 union { 10 struct { 11 unsigned bit_0:1; 12 unsigned bit_1:1; 13 }; 14 unsigned bits; 15 }; 16}; 17 18struct bit_fields_and_bits { 19 union { 20 struct { 21 unsigned bf_bit_0:1; 22 unsigned bf_bit_1:1; 23 }; 24 unsigned bf_bits; 25 }; 26}; 27 28static struct unrelated *u1, *u2; 29static struct bit_fields_and_bits *b1, *b2; 30 31static inline _Bool 32eq(int x) 33{ 34 /* 35 * TODO: Once this is fixed, enable lint in 36 * external/mit/xorg/lib/dri.old/Makefile again. 37 */ 38 39 if (x == 0) 40 /* expect+2: error: illegal use of member 'bits' [102] */ 41 /* expect+1: error: illegal use of member 'bits' [102] */ 42 return u1->bits == u2->bits; 43 44 /* 45 * The struct does not have a member named 'bits'. There's another 46 * struct with a member of that name, and in traditional C, it was 47 * possible but discouraged to access members of other structs via 48 * their plain name. 49 */ 50 /* expect+2: error: illegal use of member 'bits' [102] */ 51 /* expect+1: error: illegal use of member 'bits' [102] */ 52 return b1->bits == b2->bits; 53} 54