Skip to content

Commit a5f3366

Browse files
timotheecourirdassis
authored andcommitted
strengthen taddr.nim: add test case for nim-lang#14578; reference other issues; test cpp (nim-lang#15960)
1 parent 085788b commit a5f3366

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

tests/js/taddr.nim renamed to tests/misc/taddr.nim

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
discard """
2-
targets: "c js"
2+
targets: "c cpp js"
3+
matrix: "; -d:release"
34
"""
45

56
type T = object
@@ -79,7 +80,7 @@ someGlobalPtr[] = 10
7980
doAssert(someGlobal == 10)
8081

8182
block:
82-
# issue #14576
83+
# bug #14576
8384
# lots of these used to give: Error: internal error: genAddr: 2
8485
proc byLent[T](a: T): lent T = a
8586
proc byPtr[T](a: T): ptr T = a.unsafeAddr
@@ -89,24 +90,21 @@ block:
8990
let (x,y) = byLent(a)
9091
doAssert (x,y) == a
9192

92-
block:
93-
when defined(c) and defined(release):
94-
# bug; pending https://github.com/nim-lang/Nim/issues/14578
95-
discard
96-
else:
97-
let a = 10
98-
doAssert byLent(a) == 10
99-
let a2 = byLent(a)
100-
doAssert a2 == 10
93+
block: # (with -d:release) bug #14578
94+
let a = 10
95+
doAssert byLent(a) == 10
96+
let a2 = byLent(a)
97+
doAssert a2 == 10
10198

10299
block:
103-
let a = [11,12]
104-
doAssert byLent(a) == [11,12]
100+
when not defined(cpp): # pending bug #15958
101+
let a = [11,12]
102+
doAssert byLent(a) == [11,12]
105103
let a2 = (11,)
106104
doAssert byLent(a2) == (11,)
107105

108106
block:
109-
when defined(c) and defined(release):
107+
when (defined(c) or defined(cpp)) and defined(release):
110108
discard # probably not a bug since optimizer is free to pass by value, and `unsafeAddr` is used
111109
else:
112110
var a = @[12]
@@ -134,6 +132,6 @@ block:
134132
bar(a2).inc
135133
doAssert a2 == 13
136134

137-
block: # xxx: bug this doesn't work
135+
block: # pending bug #15959
138136
when false:
139137
proc byLent2[T](a: T): lent type(a[0]) = a[0]

0 commit comments

Comments
 (0)