Nim/tests/destructor/tuse_result_prevents_sinks.nim
flywind d102b2f54c
deprecate unsafeAddr; extend addr (#19373)
* deprecate unsafeAddr; extend addr

addr is now available for all addressable locations, unsafeAddr is deprecated and become an alias for addr

* follow @Vindaar's advice

* change the signature of addr

* unsafeAddr => addr (stdlib)

* Update changelog.md

* unsafeAddr => addr (tests)

* Revert "unsafeAddr => addr (stdlib)"

This reverts commit ab83c99c507048a8396e636bf22d55fdd84d7d1c.

* doc changes; thanks to @konsumlamm

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-01-16 11:08:38 +01:00

37 lines
578 B
Nim

discard """
output: ""
targets: "c"
"""
# bug #9594
type
Foo = object
i: int
proc `=`(self: var Foo; other: Foo) =
self.i = other.i + 1
proc `=sink`(self: var Foo; other: Foo) =
self.i = other.i
proc `=destroy`(self: var Foo) = discard
template preventCursorInference(x) =
let p = addr(x)
proc test(): Foo =
result = Foo()
let temp = result
preventCursorInference temp
doAssert temp.i > 0
return result
proc testB(): Foo =
result = Foo()
let temp = result
preventCursorInference temp
doAssert temp.i > 0
discard test()
discard testB()