Skip to content

Commit 5c7dff1

Browse files
committed
Add tests for deducing pointers
Current limitiation is that when deducing pointers from functions the order of the functions matters - the deduced functions needs to be before deduced part of code.
1 parent e348a1c commit 5c7dff1

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
fun: (inout i:int) -> *int = {
2+
return i&;
3+
}
4+
5+
fun2: (inout i:int) -> (result : *int) = {
6+
result = i&;
7+
}
8+
9+
main: (argc : int, argv : **char) -> int = {
10+
a: int = 2;
11+
pa: *int = a&;
12+
ppa: **int = pa&;
13+
14+
pa = 0; // caught
15+
16+
pa2:= ppa*;
17+
pa2 = 0; // caught
18+
19+
pa3 := a&;
20+
pa3 = 0; // caught
21+
pa3 += 2; // caught
22+
23+
ppa2 := pa2&;
24+
pa4 := ppa2*;
25+
pa4 = 0; // caught
26+
27+
pppa := ppa&;
28+
pa5 := pppa**;
29+
pa5 = 0; // caught
30+
31+
fun(a)++; // caught
32+
fp := fun(a);
33+
fp = 0; // caught
34+
35+
f := fun(a)*;
36+
37+
fp2 := fun2(a).result;
38+
fp2--; // not caught :(
39+
40+
return a * pa* * ppa**; // 8
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pure2-deducing-pointers.cpp2...
2+
pure2-deducing-pointers.cpp2(14,8): error: = - pointer assignment from null or integer is illegal
3+
pure2-deducing-pointers.cpp2(17,9): error: = - pointer assignment from null or integer is illegal
4+
pure2-deducing-pointers.cpp2(20,9): error: = - pointer assignment from null or integer is illegal
5+
pure2-deducing-pointers.cpp2(21,9): error: += - pointer assignment from null or integer is illegal
6+
pure2-deducing-pointers.cpp2(25,9): error: = - pointer assignment from null or integer is illegal
7+
pure2-deducing-pointers.cpp2(29,9): error: = - pointer assignment from null or integer is illegal
8+
pure2-deducing-pointers.cpp2(31,11): error: ++ - pointer arithmetic is illegal - use std::span or gsl::span instead
9+
pure2-deducing-pointers.cpp2(33,8): error: = - pointer assignment from null or integer is illegal
10+
==> program violates lifetime safety guarantee - see previous errors
11+
==> program violates bounds safety guarantee - see previous errors
12+

0 commit comments

Comments
 (0)