mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 06:18:51 +00:00
This commit is contained in:
@@ -498,9 +498,10 @@ proc resetLoc(p: BProc, loc: var TLoc) =
|
||||
else:
|
||||
# array passed as argument decayed into pointer, bug #7332
|
||||
# so we use getTypeDesc here rather than rdLoc(loc)
|
||||
linefmt(p, cpsStmts, "#nimZeroMem((void*)$1, sizeof($2));$n",
|
||||
[addrLoc(p.config, loc),
|
||||
getTypeDesc(p.module, loc.t, descKindFromSymKind mapTypeChooser(loc))])
|
||||
if not isOrHasImportedCppType(typ): #bug 22679
|
||||
linefmt(p, cpsStmts, "#nimZeroMem((void*)$1, sizeof($2));$n",
|
||||
[addrLoc(p.config, loc),
|
||||
getTypeDesc(p.module, loc.t, descKindFromSymKind mapTypeChooser(loc))])
|
||||
# XXX: We can be extra clever here and call memset only
|
||||
# on the bytes following the m_type field?
|
||||
genObjectInit(p, cpsStmts, loc.t, loc, constructObj)
|
||||
|
||||
50
tests/cpp/t22679.nim
Normal file
50
tests/cpp/t22679.nim
Normal file
@@ -0,0 +1,50 @@
|
||||
discard """
|
||||
cmd: "nim cpp $file"
|
||||
output:'''
|
||||
cppNZ.x = 123
|
||||
cppNZInit.x = 123
|
||||
hascpp.cppnz.x = 123
|
||||
hasCppInit.cppnz.x = 123
|
||||
hasCppCtor.cppnz.x = 123
|
||||
'''
|
||||
"""
|
||||
{.emit:"""/*TYPESECTION*/
|
||||
struct CppNonZero {
|
||||
int x = 123;
|
||||
};
|
||||
""".}
|
||||
|
||||
import sugar
|
||||
type
|
||||
CppNonZero {.importcpp, inheritable.} = object
|
||||
x: cint
|
||||
|
||||
HasCpp = object
|
||||
cppnz: CppNonZero
|
||||
|
||||
proc initCppNonZero: CppNonZero =
|
||||
CppNonZero()
|
||||
|
||||
proc initHasCpp: HasCpp =
|
||||
HasCpp()
|
||||
|
||||
proc ctorHasCpp: HasCpp {.constructor.} =
|
||||
discard
|
||||
|
||||
proc main =
|
||||
var cppNZ: CppNonZero
|
||||
dump cppNZ.x
|
||||
|
||||
var cppNZInit = initCppNonZero()
|
||||
dump cppNZInit.x
|
||||
|
||||
var hascpp: HasCpp
|
||||
dump hascpp.cppnz.x
|
||||
|
||||
var hasCppInit = initHasCpp()
|
||||
dump hasCppInit.cppnz.x
|
||||
|
||||
var hasCppCtor = ctorHasCpp()
|
||||
dump hasCppCtor.cppnz.x
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user