From 7fad6e5c701ef81c443871ec61fdca0c19c9f588 Mon Sep 17 00:00:00 2001 From: heterodoxic <122719743+heterodoxic@users.noreply.github.com> Date: Wed, 7 Jun 2023 15:15:08 +0200 Subject: [PATCH] =?UTF-8?q?fixes=20#21995:=20align=20C++=20with=20C=20back?= =?UTF-8?q?end=20behavior=20for=20empty=20raise=20state=E2=80=A6=20(#21998?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixes #21995: align C with C++ backend behavior for empty raise statements * make runtime behavior match across both C and C++ backend and all exception modes --- compiler/ccgstmts.nim | 6 +----- tests/ccgbugs/t21995.nim | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 tests/ccgbugs/t21995.nim diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 09350c0345..f536a82c13 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -779,11 +779,7 @@ proc genRaiseStmt(p: BProc, t: PNode) = else: finallyActions(p) genLineDir(p, t) - # reraise the last exception: - if p.config.exc == excCpp: - line(p, cpsStmts, "throw;\n") - else: - linefmt(p, cpsStmts, "#reraiseException();$n", []) + linefmt(p, cpsStmts, "#reraiseException();$n", []) raiseInstr(p, p.s(cpsStmts)) template genCaseGenericBranch(p: BProc, b: PNode, e: TLoc, diff --git a/tests/ccgbugs/t21995.nim b/tests/ccgbugs/t21995.nim new file mode 100644 index 0000000000..0ec88aa59a --- /dev/null +++ b/tests/ccgbugs/t21995.nim @@ -0,0 +1,9 @@ +discard """ + targets: "c cpp" + output: "Hi!" +""" + +try: + raise +except: + echo "Hi!" \ No newline at end of file