tests: rename pointer_arithmetic_should_be_checked.vv -> unsafe_required.vv (#5897)

pull/5902/head
Nick Treleaven 2020-07-20 21:04:22 +01:00 committed by GitHub
parent 53e7cb124d
commit 15ca64d81d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 4 deletions

View File

@ -0,0 +1,34 @@
vlib/v/checker/tests/unsafe_required.v:4:6: error: pointer arithmetic is only allowed in `unsafe` blocks
2 | v := 5
3 | mut p := &v
4 | p++
| ~~
5 | p += 2
6 | _ := v
vlib/v/checker/tests/unsafe_required.v:5:7: error: pointer arithmetic is only allowed in `unsafe` blocks
3 | mut p := &v
4 | p++
5 | p += 2
| ~~
6 | _ := v
7 | }
vlib/v/checker/tests/unsafe_required.v:11:14: error: pointer arithmetic is only allowed in `unsafe` blocks
9 | fn test_ptr_infix() {
10 | v := 4
11 | mut q := &v - 1
| ^
12 | q = q + 3
13 | _ := q
vlib/v/checker/tests/unsafe_required.v:12:9: error: pointer arithmetic is only allowed in `unsafe` blocks
10 | v := 4
11 | mut q := &v - 1
12 | q = q + 3
| ^
13 | _ := q
14 | _ := v
vlib/v/checker/tests/unsafe_required.v:24:7: error: method `S1.f` must be called from an `unsafe` block
22 | fn test_funcs() {
23 | s := S1{}
24 | s.f()
| ~~~
25 | }

View File

@ -0,0 +1,25 @@
fn test_ptr_assign() {
v := 5
mut p := &v
p++
p += 2
_ := v
}
fn test_ptr_infix() {
v := 4
mut q := &v - 1
q = q + 3
_ := q
_ := v
}
struct S1 {}
[unsafe_fn]
fn (s S1) f(){}
fn test_funcs() {
s := S1{}
s.f()
}