parent
963184fea6
commit
e1ed34627f
2 changed files with 18 additions and 2 deletions
|
|
@ -1645,8 +1645,14 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) =
|
||||||
putIntoDest(p, d, e, "(($1) ($2))" %
|
putIntoDest(p, d, e, "(($1) ($2))" %
|
||||||
[getClosureType(p.module, etyp, clHalfWithEnv), rdCharLoc(a)], a.storage)
|
[getClosureType(p.module, etyp, clHalfWithEnv), rdCharLoc(a)], a.storage)
|
||||||
else:
|
else:
|
||||||
putIntoDest(p, d, e, "(($1) ($2))" %
|
let srcTyp = skipTypes(e.sons[1].typ, abstractRange)
|
||||||
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
# C++ does not like direct casts from pointer to shorter integral types
|
||||||
|
if srcTyp.kind in {tyPtr, tyPointer} and etyp.kind in IntegralTypes:
|
||||||
|
putIntoDest(p, d, e, "(($1) (ptrdiff_t) ($2))" %
|
||||||
|
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
||||||
|
else:
|
||||||
|
putIntoDest(p, d, e, "(($1) ($2))" %
|
||||||
|
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
||||||
|
|
||||||
proc genCast(p: BProc, e: PNode, d: var TLoc) =
|
proc genCast(p: BProc, e: PNode, d: var TLoc) =
|
||||||
const ValueTypes = {tyFloat..tyFloat128, tyTuple, tyObject, tyArray}
|
const ValueTypes = {tyFloat..tyFloat128, tyTuple, tyObject, tyArray}
|
||||||
|
|
|
||||||
10
tests/cpp/tcasts.nim
Normal file
10
tests/cpp/tcasts.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim cpp $file"
|
||||||
|
output: ""
|
||||||
|
"""
|
||||||
|
|
||||||
|
block: #5979
|
||||||
|
var a = 'a'
|
||||||
|
var p: pointer = cast[pointer](a)
|
||||||
|
var c = cast[char](p)
|
||||||
|
doAssert(c == 'a')
|
||||||
Loading…
Add table
Add a link
Reference in a new issue