libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / flex-array-counted-by-8.c
blob058d58fb2931f8dec1f35b11cdd5070ea1ac5524
1 /* Testing the correct usage of attribute counted_by in c23, multiple
2 * definitions of the same tag in same or different scopes.
3 * { dg-do compile }
4 * { dg-options "-std=c23" }
5 */
7 /* Allowed redefinitions of the same struct in the same scope, with the
8 same counted_by attribute. */
9 struct f {
10 int b;
11 int c;
12 int a[] __attribute__ ((counted_by (b))); };
13 struct f {
14 int b;
15 int c;
16 int a[] __attribute__ ((counted_by (b))); };
17 struct f {
18 int b;
19 int c;
20 int a[]; }; /* { dg-error "redefinition of struct or union" } */
22 /* Error when the counted_by attribute is defined differently. */
23 struct f {
24 int b;
25 int c;
26 int a[] __attribute__ ((counted_by (c))); }; /* { dg-error "redefinition of struct or union" } */
28 struct h {
29 int b;
30 int c;
31 int a[] __attribute__ ((counted_by (b))); } p;
33 void test (void)
35 struct h {
36 int b;
37 int c;
38 int a[] __attribute__ ((counted_by (b))); } x;
40 p = x;
43 void test1 (void)
45 struct h {
46 int b;
47 int c;
48 int a[] __attribute__ ((counted_by (c))); } y;
50 p = y; /* { dg-error "incompatible types when assigning to type" } */
53 struct nested_f {
54 struct {
55 union {
56 int b;
57 float f;
59 int n;
61 char c[] __attribute__ ((counted_by (b)));
62 };
64 struct nested_f {
65 struct {
66 union {
67 int b;
68 float f;
70 int n;
72 char c[] __attribute__ ((counted_by (b)));
73 };
75 struct nested_f {
76 struct {
77 union {
78 int b;
79 float f;
81 int n;
83 char c[] __attribute__ ((counted_by (n)));
84 }; /* { dg-error "redefinition of struct or union" } */
86 struct nested_h {
87 struct {
88 union {
89 int b;
90 float f;
92 int n;
94 char c[] __attribute__ ((counted_by (b)));
95 } nested_p;
97 void test_2 (void)
99 struct nested_h {
100 struct {
101 union {
102 int b;
103 float f;
105 int n;
107 char c[] __attribute__ ((counted_by (b)));
108 } nested_x;
110 nested_p = nested_x;
113 void test_3 (void)
115 struct nested_h {
116 struct {
117 union {
118 int b;
119 float f;
121 int n;
123 char c[] __attribute__ ((counted_by (n)));
124 } nested_y;
126 nested_p = nested_y; /* { dg-error "incompatible types when assigning to type" } */