fixes #23306 nim cpp -r invalid code generation regression with closure iterators and try/catch-like constructions (#23317)

This commit is contained in:
Juan M Gómez
2024-02-26 10:21:03 +00:00
committed by GitHub
parent 14cdcc091f
commit 93a8b85a91
2 changed files with 14 additions and 2 deletions

View File

@@ -1037,8 +1037,8 @@ proc genTryCpp(p: BProc, t: PNode, d: var TLoc) =
inc(p.labels, 2)
let etmp = p.labels
lineCg(p, cpsStmts, "std::exception_ptr T$1_;$n", [etmp])
#init on locals, fixes #23306
lineCg(p, cpsLocals, "std::exception_ptr T$1_;$n", [etmp])
let fin = if t[^1].kind == nkFinally: t[^1] else: nil
p.nestedTryStmts.add((fin, false, 0.Natural))

12
tests/cpp/t23306.nim Normal file
View File

@@ -0,0 +1,12 @@
discard """
targets: "cpp"
"""
type K = object
h: iterator(f: K): K
iterator d(g: K): K {.closure.} =
defer:
discard
discard K(h: d)