rust/tests/fail/dangling_pointers/null_pointer_deref_zst.rs
2022-07-11 11:48:56 +00:00

9 lines
310 B
Rust

// Some optimizations remove ZST accesses, thus masking this UB.
//@compile-flags: -Zmir-opt-level=0
#[allow(deref_nullptr)]
fn main() {
let x: () = unsafe { *std::ptr::null() }; //~ ERROR: dereferencing pointer failed: null pointer is a dangling pointer
panic!("this should never print: {:?}", x);
}