mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-09 16:48:18 +00:00
simplify
This commit is contained in:
@@ -2815,15 +2815,6 @@ proc genWasMoved(p: BProc; n: PNode) =
|
||||
#linefmt(p, cpsStmts, "#nimZeroMem((void*)$1, sizeof($2));$n",
|
||||
# [addrLoc(p.config, a), getTypeDesc(p.module, a.t)])
|
||||
|
||||
proc genMoveCall(p: BProc; n: PNode; d: var TLoc) =
|
||||
n[1] = makeAddr(n[1], p.module.idgen)
|
||||
let moveSym = n[0].sym
|
||||
let oldOwner = moveSym.owner
|
||||
# TODO: sem instantiation issues, without this, C++ types are broken
|
||||
setOwner(moveSym, p.module.module)
|
||||
genCall(p, n, d)
|
||||
setOwner(moveSym, oldOwner)
|
||||
|
||||
proc genMove(p: BProc; n: PNode; d: var TLoc) =
|
||||
if n.len == 4:
|
||||
# generated by liftdestructors:
|
||||
@@ -2853,7 +2844,8 @@ proc genMove(p: BProc; n: PNode; d: var TLoc) =
|
||||
genAssignment(p, d, a, {})
|
||||
resetLoc(p, a)
|
||||
else:
|
||||
genMoveCall(p, n, d)
|
||||
n[1] = makeAddr(n[1], p.module.idgen)
|
||||
genCall(p, n, d)
|
||||
else:
|
||||
var a: TLoc = initLocExpr(p, n[1].skipAddr, {lfEnforceDeref, lfPrepareForMutation})
|
||||
genAssignment(p, d, a, {})
|
||||
|
||||
7
tests/ccgbugs2/m25800.h
Normal file
7
tests/ccgbugs2/m25800.h
Normal file
@@ -0,0 +1,7 @@
|
||||
/*TYPESECTION*/
|
||||
struct CppRef {
|
||||
int* data;
|
||||
CppRef() : data(new int(42)) {}
|
||||
~CppRef() { delete data; data = nullptr; }
|
||||
void reset() { delete data; data = nullptr; }
|
||||
};
|
||||
@@ -4,16 +4,9 @@ discard """
|
||||
"""
|
||||
|
||||
# Bug Report 1: {.importcpp.} on =wasMoved generates invalid preprocessor directive #.
|
||||
{.emit: """/*TYPESECTION*/
|
||||
struct CppRef {
|
||||
int* data;
|
||||
CppRef() : data(new int(42)) {}
|
||||
~CppRef() { delete data; data = nullptr; }
|
||||
void reset() { delete data; data = nullptr; }
|
||||
};
|
||||
""".}
|
||||
|
||||
type CppRef* {.importcpp, bycopy, noInit.} = object
|
||||
|
||||
type CppRef* {.importcpp, bycopy, noInit, header: "m25800.h".} = object
|
||||
|
||||
proc `=destroy`(x: var CppRef) {.importcpp: "#.~CppRef()".}
|
||||
proc `=wasMoved`(x: var CppRef) {.importcpp: "#.reset()".}
|
||||
|
||||
Reference in New Issue
Block a user