v2 / vlib / v / checker / tests / unsafe_pointer_arithmetic_should_be_checked.vv
36 lines · 32 sloc · 363 bytes · 219dcb12cfc9ddf782258c89ba3cd361a3d569c9
Raw
1fn test_ptr_assign() {
2 mut v := 5
3 mut p := &v
4 p++
5 p += 2
6 _ := v
7}
8
9fn test_ptr_infix() {
10 v := 4
11 mut q := &v - 1
12 q = q + 3
13 _ := q
14 _ := v
15}
16
17struct Foo {
18 x int
19}
20
21fn test_struct_ptr_infix() {
22 v := Foo{}
23 mut q := &v - 1
24 q = q + 3
25 _ := q
26 _ := v
27}
28
29fn test_ptr_to_struct_ptr_infix() {
30 v := Foo{}
31 p := &v
32 mut q := &p - 1
33 q = q + 3
34 _ := q
35 _ := p
36}
37