msg_102.c revision 1.6
11.6Srillig/* $NetBSD: msg_102.c,v 1.6 2023/06/30 21:06:18 rillig Exp $ */ 21.1Srillig# 3 "msg_102.c" 31.1Srillig 41.4Srillig// Test for message: illegal use of member '%s' [102] 51.1Srillig 61.3Srillig// Anonymous members are defined in C11 6.7.2.1p2. 71.3Srillig 81.5Srilligstruct unrelated { 91.3Srillig union { 101.3Srillig struct { 111.3Srillig unsigned bit_0:1; 121.3Srillig unsigned bit_1:1; 131.3Srillig }; 141.3Srillig unsigned bits; 151.3Srillig }; 161.3Srillig}; 171.3Srillig 181.5Srilligstruct bit_fields_and_bits { 191.5Srillig union { 201.5Srillig struct { 211.5Srillig unsigned bf_bit_0:1; 221.5Srillig unsigned bf_bit_1:1; 231.5Srillig }; 241.5Srillig unsigned bf_bits; 251.5Srillig }; 261.5Srillig}; 271.5Srillig 281.5Srilligstatic struct unrelated *u1, *u2; 291.5Srilligstatic struct bit_fields_and_bits *b1, *b2; 301.5Srillig 311.3Srilligstatic inline _Bool 321.5Srilligeq(int x) 331.3Srillig{ 341.5Srillig if (x == 0) 351.6Srillig /* Accessing a member from an unnamed struct member. */ 361.5Srillig return u1->bits == u2->bits; 371.5Srillig 381.5Srillig /* 391.5Srillig * The struct does not have a member named 'bits'. There's another 401.5Srillig * struct with a member of that name, and in traditional C, it was 411.5Srillig * possible but discouraged to access members of other structs via 421.5Srillig * their plain name. 431.5Srillig */ 441.4Srillig /* expect+2: error: illegal use of member 'bits' [102] */ 451.4Srillig /* expect+1: error: illegal use of member 'bits' [102] */ 461.5Srillig return b1->bits == b2->bits; 471.3Srillig} 48