From 2114414099993d5da4627645454214a7ff306f1e Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:46:39 +0800 Subject: [PATCH] fixes #19977; rework inlining of 'var openarray' iterators for C++ (#23258) fixes #19977 (cherry picked from commit f7c6e04cfbc44c225c123d724745840585561ac5) --- compiler/transf.nim | 3 ++- tests/iter/titervaropenarray.nim | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/transf.nim b/compiler/transf.nim index 961ac49672..56d8d35abc 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -472,7 +472,8 @@ proc transformYield(c: PTransf, n: PNode): PNode = proc transformAddrDeref(c: PTransf, n: PNode, kinds: TNodeKinds): PNode = result = transformSons(c, n) - if c.graph.config.backend == backendCpp or sfCompileToCpp in c.module.flags: return + # inlining of 'var openarray' iterators; bug #19977 + if n.typ.kind != tyOpenArray and (c.graph.config.backend == backendCpp or sfCompileToCpp in c.module.flags): return var n = result case n[0].kind of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64: diff --git a/tests/iter/titervaropenarray.nim b/tests/iter/titervaropenarray.nim index ad1192bd80..b2fe71cebf 100644 --- a/tests/iter/titervaropenarray.nim +++ b/tests/iter/titervaropenarray.nim @@ -1,6 +1,6 @@ discard """ output: "123" - targets: "c" + targets: "c cpp" """ # Try to break the transformation pass: iterator iterAndZero(a: var openArray[int]): int =