diff options
Diffstat (limited to 'tests/ui/const-ptr/out_of_bounds_read.rs')
-rw-r--r-- | tests/ui/const-ptr/out_of_bounds_read.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/ui/const-ptr/out_of_bounds_read.rs b/tests/ui/const-ptr/out_of_bounds_read.rs new file mode 100644 index 000000000..9dd669180 --- /dev/null +++ b/tests/ui/const-ptr/out_of_bounds_read.rs @@ -0,0 +1,15 @@ +// error-pattern: evaluation of constant value failed + +#![feature(const_ptr_read)] + +fn main() { + use std::ptr; + + const DATA: [u32; 1] = [42]; + + const PAST_END_PTR: *const u32 = unsafe { DATA.as_ptr().add(1) }; + + const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) }; + const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() }; + const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() }; +} |