54 lines · c
1// RUN: %clang_cc1 -verify -std=c2y %s2// RUN: %clang_cc1 -verify -std=c23 %s3// RUN: %clang_cc1 -verify -std=c17 %s4// RUN: %clang_cc1 -verify -std=c11 %s5// RUN: %clang_cc1 -verify -std=c99 %s6// RUN: %clang_cc1 -verify -std=c89 %s7 8/* WG14 N3532: Yes9 * Member access of an incomplete object10 *11 * Verify that the first operand to the . or -> operators is a complete object12 * type.13 */14 15struct S {16 int i;17};18 19union U {20 int i;21};22 23void good_test(void) {24 struct S s;25 struct S *s_ptr = &s;26 union U u;27 union U *u_ptr = &u;28 29 // Complete object type, correctly named member.30 s.i = 10;31 s_ptr->i = 10;32 u.i = 10;33 u_ptr->i = 10;34}35 36void bad_test(void) {37 struct Incomplete *s_ptr; /* expected-note 2 {{forward declaration of 'struct Incomplete'}} */38 union AlsoIncomplete *u_ptr; /* expected-note 2 {{forward declaration of 'union AlsoIncomplete'}} */39 struct S s;40 union U u;41 42 // Incomplete object type.43 s_ptr->i = 10; /* expected-error {{incomplete definition of type 'struct Incomplete'}} */44 u_ptr->i = 10; /* expected-error {{incomplete definition of type 'union AlsoIncomplete'}} */45 46 (*s_ptr).i = 10; /* expected-error {{incomplete definition of type 'struct Incomplete'}} */47 (*u_ptr).i = 10; /* expected-error {{incomplete definition of type 'union AlsoIncomplete'}} */48 49 // Complete object type, no named member.50 s.f = "test"; /* expected-error {{no member named 'f' in 'struct S'}} */51 u.f = "test"; /* expected-error {{no member named 'f' in 'union U'}} */52}53 54