rust/tests/compile-fail/null_pointer_deref_zst.rs

9 lines
293 B
Rust
Raw Normal View History

2021-03-25 06:44:30 -05:00
// Some optimizations remove ZST accesses, thus masking this UB.
// compile-flags: -Zmir-opt-level=0
2021-04-15 03:00:39 -05:00
#[allow(deref_nullptr)]
fn main() {
2020-05-01 07:43:59 -05:00
let x: () = unsafe { *std::ptr::null() }; //~ ERROR memory access failed: 0x0 is not a valid pointer
panic!("this should never print: {:?}", x);
}