From a33ccd67b172d4cc6fd66d1841919a92ad96c7e1 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 15 Apr 2026 07:31:11 +0900 Subject: [PATCH] class.h: avoid C99 designated initializers in MRB_MT_ENTRY Older C++ compilers (notably gcc 4.x) do not support C99 struct field designators (.func = ...) even as an extension, which blocks building mruby when it is included from a C++ translation unit under such toolchains. Reorder union mrb_mt_ptr so that mrb_func_t is the first member, and switch MRB_MT_ENTRY to positional aggregate initialization. Both are compatible with pre-C99 / pre-C++20 compilers. Fixes #6789 Co-authored-by: Claude --- include/mruby/class.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/mruby/class.h b/include/mruby/class.h index fdac8ef9f..33c0b90e7 100644 --- a/include/mruby/class.h +++ b/include/mruby/class.h @@ -100,10 +100,13 @@ void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c); typedef int (mrb_mt_foreach_func)(mrb_state*,mrb_sym,mrb_method_t,void*); MRB_API void mrb_mt_foreach(mrb_state*, struct RClass*, mrb_mt_foreach_func*, void*); -/* ROM method table types for static method registration */ +/* ROM method table types for static method registration. + * NOTE: `func` is kept as the first union member so that positional + * aggregate initialization in MRB_MT_ENTRY works without C99 + * designated initializers (required for legacy C++ compilers). */ union mrb_mt_ptr { - const struct RProc *proc; mrb_func_t func; + const struct RProc *proc; }; /* entry combining function pointer, symbol key, and flags */ @@ -128,7 +131,7 @@ typedef struct mrb_mt_tbl { /* ROM table entry: 3rd param is MRB_ARGS_*() optionally OR'd with MRB_MT_PRIVATE. */ #define MRB_MT_ENTRY(fn, sym, flags) \ - { { .func = (fn) }, (sym), (flags) | MRB_MT_FUNC } + { { (fn) }, (sym), (flags) | MRB_MT_FUNC } #define MRB_MT_ASPEC(flags) ((mrb_aspec)((flags) & 0xffffff)) /* "removed" tombstone: MRB_MT_FUNC flag set with NULL function pointer.