mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
This commit is contained in:
@@ -482,7 +482,10 @@ include ccgreset
|
||||
proc resetLoc(p: BProc, loc: var TLoc) =
|
||||
let containsGcRef = optSeqDestructors notin p.config.globalOptions and containsGarbageCollectedRef(loc.t)
|
||||
let typ = skipTypes(loc.t, abstractVarRange)
|
||||
if isImportedCppType(typ): return
|
||||
if isImportedCppType(typ):
|
||||
var didGenTemp = false
|
||||
linefmt(p, cpsStmts, "$1 = $2;$n", [rdLoc(loc), genCppInitializer(p.module, p, typ, didGenTemp)])
|
||||
return
|
||||
if optSeqDestructors in p.config.globalOptions and typ.kind in {tyString, tySequence}:
|
||||
assert loc.snippet != ""
|
||||
|
||||
|
||||
17
tests/cpp/23962.h
Normal file
17
tests/cpp/23962.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
|
||||
struct Foo {
|
||||
|
||||
Foo(int inX): x(inX) {
|
||||
std::cout << "Ctor Foo(" << x << ")\n";
|
||||
}
|
||||
~Foo() {
|
||||
std::cout << "Destory Foo(" << x << ")\n";
|
||||
}
|
||||
|
||||
void print() {
|
||||
std::cout << "Foo.x = " << x << '\n';
|
||||
}
|
||||
|
||||
int x;
|
||||
};
|
||||
32
tests/cpp/t23962.nim
Normal file
32
tests/cpp/t23962.nim
Normal file
@@ -0,0 +1,32 @@
|
||||
discard """
|
||||
cmd: "nim cpp $file"
|
||||
output: '''
|
||||
Ctor Foo(-1)
|
||||
Destory Foo(-1)
|
||||
Ctor Foo(-1)
|
||||
Destory Foo(-1)
|
||||
Ctor Foo(-1)
|
||||
Destory Foo(-1)
|
||||
Foo.x = 1
|
||||
Foo.x = 2
|
||||
Foo.x = -1
|
||||
'''
|
||||
"""
|
||||
|
||||
type
|
||||
Foo {.importcpp, header: "23962.h".} = object
|
||||
x: cint
|
||||
|
||||
proc print(f: Foo) {.importcpp.}
|
||||
|
||||
#also tests the right constructor is used
|
||||
proc makeFoo(x: int32 = -1): Foo {.importcpp:"Foo(#)", constructor.}
|
||||
|
||||
proc test =
|
||||
var xs = newSeq[Foo](3)
|
||||
xs[0].x = 1
|
||||
xs[1].x = 2
|
||||
for x in xs:
|
||||
x.print
|
||||
|
||||
test()
|
||||
Reference in New Issue
Block a user