mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
fixes #23306 nim cpp -r invalid code generation regression with closure iterators and try/catch-like constructions (#23317)
This commit is contained in:
@@ -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
12
tests/cpp/t23306.nim
Normal 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)
|
||||
Reference in New Issue
Block a user