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