Debian Codegraph @

gcc/testsuite/gcc.dg/flex-array-counted-by.c

raw
1 /* Testing the correct usage of attribute counted_by. */
2 /* { dg-do compile } */
3 /* { dg-options "-O2" } */
4 /* { dg-require-effective-target wchar } */
5
6 #include <wchar.h>
7
8 int size;
9 int x __attribute ((counted_by (size))); /* { dg-error "attribute is not allowed for a non-field declaration" } */
10
11 struct trailing {
12 int count;
13 int field __attribute ((counted_by (count))); /* { dg-error "attribute is not allowed for a non-array field" } */
14 };
15
16 struct trailing_1 {
17 int count;
18 int array_1[0] __attribute ((counted_by (count))); /* { dg-error "attribute is not allowed for a non-flexible array member field" } */
19 };
20
21 int count;
22 struct trailing_array_2 {
23 int count;
24 int array_2[] __attribute ((counted_by ("count"))); /* { dg-error "argument is not an identifier" } */
25 };
26
27 struct trailing_array_3 {
28 int other;
29 int array_3[] __attribute ((counted_by (L"count"))); /* { dg-error "argument is not an identifier" } */
30 };
31
32 struct trailing_array_4 {
33 int other;
34 int array_4[] __attribute ((counted_by (count))); /* { dg-error "attribute is not a field declaration in the same structure as" } */
35 };
36
37 int count;
38 struct trailing_array_5 {
39 float count;
40 int array_5[] __attribute ((counted_by (count))); /* { dg-error "attribute is not a field declaration with an integer type" } */
41 };
42
43 struct trailing_array_6 {
44 int count;
45 int array_6[] __attribute ((counted_by (count))) __attribute ((counted_by (count)));
46 };
47
48 struct trailing_array_7 {
49 int count1;
50 int count2;
51 int array_7[] __attribute ((counted_by (count1))) __attribute ((counted_by (count2))); /* { dg-error "conflicts with previous declaration" } */
52 };
53
54 struct trailing_array_8 {
55 _Bool count;
56 int array_8[] __attribute ((counted_by (count)));
57 };
58
59 enum week {Mon, Tue, Wed};
60 struct trailing_array_9 {
61 enum week days;
62 int array_9[] __attribute ((counted_by (days)));
63 };