From 37fac6c089bd808d4b373717e18789553b95e7de Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 31 Oct 2022 16:18:15 +0900 Subject: [PATCH] throw.h: avoid using static member in C++ struct; fix #5846 The initialization causes linkage error with gcc (not clang), caused by the following gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86254 --- include/mruby/throw.h | 9 +++++---- src/vm.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/mruby/throw.h b/include/mruby/throw.h index 52171e9b0..8ec1aa7ae 100644 --- a/include/mruby/throw.h +++ b/include/mruby/throw.h @@ -52,14 +52,15 @@ typedef mrb_int mrb_jmpbuf_impl; #endif +#if defined(MRB_USE_CXX_EXCEPTION) +extern mrb_int mrb_jmpbuf_id; +#endif + struct mrb_jmpbuf { mrb_jmpbuf_impl impl; #if defined(MRB_USE_CXX_EXCEPTION) - static mrb_int jmpbuf_id; -# if defined(__cplusplus) - mrb_jmpbuf() : impl(jmpbuf_id++) {} -# endif + mrb_jmpbuf() : impl(mrb_jmpbuf_id++) {} #endif }; diff --git a/src/vm.c b/src/vm.c index 553e68b11..586585079 100644 --- a/src/vm.c +++ b/src/vm.c @@ -3127,5 +3127,5 @@ mrb_top_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int st # if !defined(MRB_USE_CXX_ABI) } /* end of extern "C" */ # endif -mrb_int mrb_jmpbuf::jmpbuf_id = 0; +mrb_int mrb_jmpbuf_id = 0; #endif