xref: /aosp_15_r20/external/clang/test/Sema/struct-compat.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li /* RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify
2*67e74705SXin Li  */
3*67e74705SXin Li 
4*67e74705SXin Li extern struct {int a;} x; // expected-note {{previous declaration is here}}
5*67e74705SXin Li extern struct {int a;} x; // expected-error {{redeclaration of 'x'}}
6*67e74705SXin Li 
7*67e74705SXin Li struct x;
a(struct x * b)8*67e74705SXin Li int a(struct x* b) {
9*67e74705SXin Li // Per C99 6.7.2.3, since the outer and inner "struct x"es have different
10*67e74705SXin Li // scopes, they don't refer to the same type, and are therefore incompatible
11*67e74705SXin Li struct x {int a;} *c = b; // expected-warning {{incompatible pointer types}}
12*67e74705SXin Li }
13*67e74705SXin Li 
14*67e74705SXin Li struct x {int a;} r;
b()15*67e74705SXin Li int b() {
16*67e74705SXin Li struct x {char x;} s = r; // expected-error {{initializing 'struct x' with an expression of incompatible type 'struct x'}}
17*67e74705SXin Li }
18