Debian Codegraph @

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

raw
1 /*
2 * { dg-do compile }
3 * { dg-options "-std=c23 -pedantic-errors" }
4 */
5
6 // (in-)completeness
7
8 struct foo {
9 char x[10];
10 } x;
11
12 // complete, same type
13
14 struct foo {
15 _Static_assert(_Generic(&x, struct foo*: 1, default: 0));
16 char x[_Generic(&x, struct foo*: 10, default: 1)];
17 _Static_assert(_Generic(0, struct foo: 0, default: 1));
18 };
19
20 // incomplete, same type
21
22 struct bar* p;
23 struct bar {
24 _Static_assert(_Generic(p, struct bar*: 1, default: 0));
25 char x[_Generic(p, struct bar*: 10, default: 1)];
26 _Static_assert(_Generic(0, struct bar: 0, default: 1)); /* { dg-error "incomplete type" } */
27 };
28
29 struct bar {
30 char x[10];
31 };
32
33 struct h *hp;
34
35 void f(void)
36 {
37 // again incomplete, different type
38
39 struct foo {
40 char x[_Generic(&x, struct foo*: 1, default: 10)];
41 _Static_assert(_Generic(0, struct foo: 0, default: 1)); /* { dg-error "incomplete type" } */
42 };
43
44 struct foo z;
45 _Static_assert(10 == sizeof(z.x), "");
46
47 // still incomplete, different type
48
49 struct h {
50 char x[_Generic(hp, struct h*: 1, default: 10)];
51 _Static_assert(_Generic(0, struct h: 0, default: 1)); /* { dg-error "incomplete type" } */
52 };
53
54 struct h y;
55 _Static_assert(10 == sizeof(y.x), "");
56 }
57
58