]>
Commit | Line | Data |
---|---|---|
1b1a35ee XL |
1 | // check-pass |
2 | ||
3 | // This test exhibits undefined behavior, but it is very expensive and complex to check for such | |
4 | // UB in constants. | |
5 | // Thus, we do not detect it if you create references to statics in ways that are UB. | |
6 | ||
8faf50e0 XL |
7 | enum Foo { |
8 | A = 5, | |
9 | B = 42, | |
0531ce1d | 10 | } |
8faf50e0 XL |
11 | enum Bar { |
12 | C = 42, | |
13 | D = 99, | |
14 | } | |
e1599b0c | 15 | #[repr(C)] |
8faf50e0 XL |
16 | union Union { |
17 | foo: &'static Foo, | |
18 | bar: &'static Bar, | |
a1dfa0c6 | 19 | u8: &'static u8, |
8faf50e0 | 20 | } |
a1dfa0c6 | 21 | static BAR: u8 = 5; |
1b1a35ee XL |
22 | static FOO: (&Foo, &Bar) = unsafe { |
23 | ( | |
24 | // undefined behavior | |
25 | Union { u8: &BAR }.foo, | |
26 | Union { u8: &BAR }.bar, | |
27 | ) | |
28 | }; | |
29 | static FOO2: (&Foo, &Bar) = unsafe { (std::mem::transmute(&BAR), std::mem::transmute(&BAR)) }; | |
30 | //^ undefined behavior | |
0531ce1d | 31 | |
5bcae85e | 32 | fn main() {} |