rust/tests/fail/dangling_pointers/null_pointer_deref_zst.rs

9 lines
310 B
Rust
Raw Normal View History

2021-03-25 06:44:30 -05:00
// Some optimizations remove ZST accesses, thus masking this UB.
2022-07-08 11:08:32 -05:00
//@compile-flags: -Zmir-opt-level=0
2021-03-25 06:44:30 -05:00
2021-04-15 03:00:39 -05:00
#[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);
}