| 1 |
// RUN: %clang_cc1 -verify -std=c2y %s |
| 2 |
// RUN: %clang_cc1 -verify -std=c23 %s |
| 3 |
// RUN: %clang_cc1 -verify -std=c17 %s |
| 4 |
// RUN: %clang_cc1 -verify -std=c11 %s |
| 5 |
// RUN: %clang_cc1 -verify -std=c99 %s |
| 6 |
// RUN: %clang_cc1 -verify -std=c89 %s |
| 7 |
|
| 8 |
/* WG14 N3532: Yes |
| 9 |
* Member access of an incomplete object |
| 10 |
* |
| 11 |
* Verify that the first operand to the . or -> operators is a complete object |
| 12 |
* type. |
| 13 |
*/ |
| 14 |
|
| 15 |
struct S { |
| 16 |
int i; |
| 17 |
}; |
| 18 |
|
| 19 |
union U { |
| 20 |
int i; |
| 21 |
}; |
| 22 |
|
| 23 |
void 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 |
|
| 36 |
void 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 |
|