Skip to content

Commit 008e94f

Browse files
committed
Add anonymous field inside struct
1 parent eccd08a commit 008e94f

5 files changed

Lines changed: 114 additions & 129 deletions

File tree

tests/unit/anonymous-enum.cpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

tests/unit/anonymous_enum.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <assert.h>
2+
3+
enum {
4+
FIRST_A,
5+
FIRST_B,
6+
};
7+
8+
struct S {
9+
int a;
10+
11+
enum {
12+
SECOND_A,
13+
SECOND_B,
14+
};
15+
};
16+
17+
typedef enum {
18+
TD_A,
19+
TD_B,
20+
} TdEnum;
21+
22+
struct WithAnonField {
23+
int a;
24+
enum {
25+
FIELD_A,
26+
FIELD_B,
27+
} field;
28+
};
29+
30+
int main() {
31+
enum {
32+
THIRD_A,
33+
THIRD_B,
34+
};
35+
36+
assert(FIRST_A == 0);
37+
assert(FIRST_B == 1);
38+
39+
assert(S::SECOND_A == 0);
40+
assert(S::SECOND_B == 1);
41+
42+
assert(THIRD_A == 0);
43+
assert(THIRD_B == 1);
44+
45+
TdEnum td = TD_A;
46+
assert(td == TD_A);
47+
td = TD_B;
48+
assert(td == TD_B);
49+
50+
WithAnonField w;
51+
w.field = WithAnonField::FIELD_A;
52+
assert(w.field == WithAnonField::FIELD_A);
53+
w.field = WithAnonField::FIELD_B;
54+
assert(w.field == WithAnonField::FIELD_B);
55+
56+
return 0;
57+
};

tests/unit/anonymous_enum_c.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <assert.h>
2+
3+
enum {
4+
FIRST_A,
5+
FIRST_B,
6+
};
7+
8+
struct S {
9+
int a;
10+
11+
enum {
12+
SECOND_A,
13+
SECOND_B,
14+
};
15+
};
16+
17+
typedef enum {
18+
TD_A,
19+
TD_B,
20+
} TdEnum;
21+
22+
struct WithAnonField {
23+
int a;
24+
enum {
25+
FIELD_A,
26+
FIELD_B,
27+
} field;
28+
};
29+
30+
int main() {
31+
enum {
32+
THIRD_A,
33+
THIRD_B,
34+
};
35+
36+
assert(FIRST_A == 0);
37+
assert(FIRST_B == 1);
38+
39+
assert(SECOND_A == 0);
40+
assert(SECOND_B == 1);
41+
42+
assert(THIRD_A == 0);
43+
assert(THIRD_B == 1);
44+
45+
TdEnum td = TD_A;
46+
assert(td == TD_A);
47+
td = TD_B;
48+
assert(td == TD_B);
49+
50+
struct WithAnonField w;
51+
w.field = FIELD_A;
52+
assert(w.field == FIELD_A);
53+
w.field = FIELD_B;
54+
assert(w.field == FIELD_B);
55+
56+
return 0;
57+
};

tests/unit/out/refcount/anonymous-enum.rs

Lines changed: 0 additions & 51 deletions
This file was deleted.

tests/unit/out/unsafe/anonymous-enum.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)