Debian Codegraph @

gcc/testsuite/gcc.dg/c23-tag-1.c

raw
1 /*
2 * { dg-do compile }
3 * { dg-options "-std=c23" }
4 */
5
6 // allowed and forbidden redefinitions of the same struct/union in the same scope
7
8 typedef struct p { int a; } pd_t;
9 typedef struct p { int a; } pd_t;
10
11 typedef struct bar { int x; } X;
12 typedef struct bar { float x; } Y; /* { dg-error "redefinition of struct or union" } */
13
14 void test(void)
15 {
16 struct foo { int x; };
17 struct foo { float x; }; /* { dg-error "redefinition of struct or union" } */
18 }
19
20 struct aa { int a; };
21
22 void f(void)
23 {
24 typedef struct aa A;
25 struct bb { struct aa a; } x;
26 struct aa { int a; };
27 typedef struct aa A; /* { dg-error "redefinition" } */
28 struct bb { struct aa a; } y; /* { dg-error "redefinition of struct or union" } */
29 (void)x; (void)y;
30 }
31
32
33
34 void h(void)
35 {
36 struct a2 { int a; };
37 {
38 typedef struct a2 A;
39 struct b2 { struct a2 a; } x;
40 struct a2 { int a; };
41 typedef struct a2 A; /* { dg-error "redefinition" } */
42 struct b2 { struct a2 a; } y; /* { dg-error "redefinition of struct or union" } */
43 (void)x; (void)y;
44 }
45 }
46
47
48 union cc { int x; float y; } z;
49 union cc { int x; float y; } z1;
50 union cc { float y; int x; } z2; /* { dg-error "redefinition of struct or union" } */
51
52 void g(void)
53 {
54 struct s { int a; };
55 struct s { int a; } x0;
56 struct p { struct s c; } y1 = { x0 };
57 struct p { struct s { int a; } c; } y = { x0 };
58 }
59
60 struct q { struct { int a; }; };
61 struct q { struct { int a; }; };
62 struct q { int a; }; /* { dg-error "redefinition of struct or union" } */
63
64 struct r { int a; char b[]; };
65 struct r { int a; char b[]; };
66 struct r { int a; char b[1]; }; /* { dg-error "redefinition of struct or union" } */
67