tcodegen.nim 954 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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]
  24. block: # bug #22354
  25. type Object = object
  26. foo: int
  27. proc takeFoo(self: var Object): int =
  28. result = self.foo
  29. self.foo = 999
  30. proc doSomething(self: var Object; foo: int = self.takeFoo()) =
  31. discard
  32. proc main() =
  33. var obj = Object(foo: 2)
  34. obj.doSomething()
  35. doAssert obj.foo == 999
  36. main()