tcodegen.nim 582 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. targets: "c cpp"
  3. """
  4. # bug #19094
  5. type
  6. X = object
  7. filler: array[2048, int]
  8. innerAddress: uint
  9. proc initX(): X =
  10. result.innerAddress = cast[uint](result.addr)
  11. proc initXInPlace(x: var X) =
  12. x.innerAddress = cast[uint](x.addr)
  13. block: # NRVO1
  14. var x = initX()
  15. let innerAddress = x.innerAddress
  16. let outerAddress = cast[uint](x.addr)
  17. doAssert(innerAddress == outerAddress) # [OK]
  18. block: # NRVO2
  19. var x: X
  20. initXInPlace(x)
  21. let innerAddress = x.innerAddress
  22. let outerAddress = cast[uint](x.addr)
  23. doAssert(innerAddress == outerAddress) # [OK]