1 #![feature(rustc_attrs)]
2
3 // Various tests around the behavior of zero-sized arrays and
4 // unions. This matches the behavior of modern C compilers, though
5 // older compilers (and sometimes clang) treat `T[0]` as a "flexible
6 // array member". See more
7 // details in #56877.
8
9 #[derive(Copy, Clone)]
10 #[repr(C)]
11 struct Empty { }
12
13 #[derive(Copy, Clone)]
14 #[repr(C)]
15 struct Empty2 {
16 e: Empty
17 }
18
19 #[derive(Copy, Clone)]
20 #[repr(C)]
21 struct Empty3 {
22 z: [f32; 0],
23 }
24
25 #[derive(Copy, Clone)]
26 #[repr(C)]
27 struct Empty4 {
28 e: Empty3
29 }
30
31 #[repr(C)]
32 union U1 {
33 s: Empty
34 }
35
36 #[repr(C)]
37 union U2 {
38 s: Empty2
39 }
40
41 #[repr(C)]
42 union U3 {
43 s: Empty3
44 }
45
46 #[repr(C)]
47 union U4 {
48 s: Empty4
49 }
50
51 #[repr(C)]
52 struct Baz1 {
53 x: f32,
54 y: f32,
55 u: U1,
56 }
57
58 #[rustc_layout(homogeneous_aggregate)]
59 type TestBaz1 = Baz1;
60 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous
61
62 #[repr(C)]
63 struct Baz2 {
64 x: f32,
65 y: f32,
66 u: U2,
67 }
68
69 #[rustc_layout(homogeneous_aggregate)]
70 type TestBaz2 = Baz2;
71 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous
72
73 #[repr(C)]
74 struct Baz3 {
75 x: f32,
76 y: f32,
77 u: U3,
78 }
79
80 #[rustc_layout(homogeneous_aggregate)]
81 type TestBaz3 = Baz3;
82 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous
83
84 #[repr(C)]
85 struct Baz4 {
86 x: f32,
87 y: f32,
88 u: U4,
89 }
90
91 #[rustc_layout(homogeneous_aggregate)]
92 type TestBaz4 = Baz4;
93 //~^ ERROR homogeneous_aggregate: Ok(Homogeneous
94
main()95 fn main() { }
96