rust/tests/compile-fail/null_pointer_deref_zst.rs
2021-07-16 10:10:12 +02:00

9 lines
301 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: 0x0 is not a valid pointer
panic!("this should never print: {:?}", x);
}