Skip to content

Commit 196e93f

Browse files
ringaboutnarimiran
authored andcommitted
[add testcase] NRVO does not occur with init procedures (#19462)
* [add testcase] NRVO does not occur with init procedures close #19094 * Update tests/ccgbugs2/tcodegen.nim (cherry picked from commit 33cd883)
1 parent 70478d3 commit 196e93f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/ccgbugs2/tcodegen.nim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
discard """
2+
targets: "c cpp"
3+
"""
4+
5+
# bug #19094
6+
type
7+
X = object
8+
filler: array[2048, int]
9+
innerAddress: uint
10+
11+
proc initX(): X =
12+
result.innerAddress = cast[uint](result.addr)
13+
14+
proc initXInPlace(x: var X) =
15+
x.innerAddress = cast[uint](x.addr)
16+
17+
block: # NRVO1
18+
var x = initX()
19+
let innerAddress = x.innerAddress
20+
let outerAddress = cast[uint](x.addr)
21+
doAssert(innerAddress == outerAddress) # [OK]
22+
23+
block: # NRVO2
24+
var x: X
25+
initXInPlace(x)
26+
let innerAddress = x.innerAddress
27+
let outerAddress = cast[uint](x.addr)
28+
doAssert(innerAddress == outerAddress) # [OK]

0 commit comments

Comments
 (0)