fixes #22680 Nim zero clear an object inherits C++ imported class when a proc return it (#22684)

This commit is contained in:
Juan M Gómez
2023-09-11 11:55:11 +01:00
committed by GitHub
parent b1a8d6976f
commit 7e86cd6fa7
2 changed files with 60 additions and 3 deletions

50
tests/cpp/t22680.nim Normal file
View File

@@ -0,0 +1,50 @@
discard """
cmd: "nim cpp $file"
output:'''
cppNZ.x = 123
cppNZInit.x = 123
inheritCpp.x = 123
inheritCppInit.x = 123
inheritCppCtor.x = 123
'''
"""
import std/sugar
{.emit:"""/*TYPESECTION*/
struct CppNonZero {
int x = 123;
};
""".}
type
CppNonZero {.importcpp, inheritable.} = object
x: cint
InheritCpp = object of CppNonZero
proc initCppNonZero: CppNonZero =
CppNonZero()
proc initInheritCpp: InheritCpp =
InheritCpp()
proc ctorInheritCpp: InheritCpp {.constructor.} =
discard
proc main =
var cppNZ: CppNonZero
dump cppNZ.x
var cppNZInit = initCppNonZero()
dump cppNZInit.x
var inheritCpp: InheritCpp
dump inheritCpp.x
var inheritCppInit = initInheritCpp()
dump inheritCppInit.x
var inheritCppCtor = ctorInheritCpp()
dump inheritCppCtor.x
main()