From e2b6021630a00e5acc0487a779b25e6701c344d0 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 13 Dec 2024 05:56:41 +0800 Subject: [PATCH] fixes #22101; std/pegs with nim cpp --mm:orc --exceptions:goto creates invalid C++ (#24531) fixes #22101 The old implementation generates `auto T = value;` for the cpp backend which causes problems for goto exceptions. This PR puts the declaration of `T` to the cpsLocals parts and makes it compatible with goto exceptions. (cherry picked from commit f7a461a30cfb2e1800ff63865a5b8f6c498f48a1) --- compiler/ccgcalls.nim | 2 +- tests/stdlib/tpegs.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 788f7a470b..0bf16ba9f8 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -135,7 +135,7 @@ proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, d.snippet = pl excl d.flags, lfSingleUse else: - if d.k == locNone and p.splitDecls == 0: + if d.k == locNone and p.splitDecls == 0 and p.config.exc != excGoto: d = getTempCpp(p, typ.returnType, pl) else: if d.k == locNone: d = getTemp(p, typ.returnType) diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim index da3fc14b7b..0c1fe1ef32 100644 --- a/tests/stdlib/tpegs.nim +++ b/tests/stdlib/tpegs.nim @@ -1,5 +1,5 @@ discard """ - matrix: "--mm:refc; --mm:orc" + matrix: "--mm:refc; --mm:orc; --exceptions:goto" targets: "c cpp js" output: ''' PEG AST traversal output