From f7a461a30cfb2e1800ff63865a5b8f6c498f48a1 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. --- 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 b18ea017ed..aaad53b64b 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -141,7 +141,7 @@ proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, d.snippet = extract(result) 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, extract(result)) else: if d.k == locNone: d = getTemp(p, typ.returnType) diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim index 32aab82f2b..18753a9bea 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