Skip to content

Commit

Permalink
[add testcase] NRVO does not occur with init procedures (#19462)
Browse files Browse the repository at this point in the history
* [add testcase] NRVO does not occur with init procedures

close #19094

* Update tests/ccgbugs2/tcodegen.nim
  • Loading branch information
ringabout authored Jan 29, 2022
1 parent cb894c7 commit 33cd883
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/ccgbugs2/tcodegen.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
discard """
targets: "c cpp"
"""

# bug #19094
type
X = object
filler: array[2048, int]
innerAddress: uint

proc initX(): X =
result.innerAddress = cast[uint](result.addr)

proc initXInPlace(x: var X) =
x.innerAddress = cast[uint](x.addr)

block: # NRVO1
var x = initX()
let innerAddress = x.innerAddress
let outerAddress = cast[uint](x.addr)
doAssert(innerAddress == outerAddress) # [OK]

block: # NRVO2
var x: X
initXInPlace(x)
let innerAddress = x.innerAddress
let outerAddress = cast[uint](x.addr)
doAssert(innerAddress == outerAddress) # [OK]

0 comments on commit 33cd883

Please sign in to comment.