diff --git a/src/generators/cpp/cppContext.ml b/src/generators/cpp/cppContext.ml index bcf900708df..874eb7aa2dd 100644 --- a/src/generators/cpp/cppContext.ml +++ b/src/generators/cpp/cppContext.ml @@ -89,7 +89,10 @@ let hash_keys hash = !key_list let is_gc_element ctx member_type = - Gctx.defined ctx.ctx_common Define.HxcppGcGenerational && (is_object_element member_type) + Gctx.defined ctx.ctx_common Define.HxcppGcGenerational && + match member_type with + | CppAst.TCppFunction _ -> false + | _ -> is_object_element member_type let strip_file ctx file = match Gctx.defined ctx Define.AbsolutePath with | true -> Path.get_full_path file diff --git a/tests/misc/cpp/projects/Issue13001/Main.hx b/tests/misc/cpp/projects/Issue13001/Main.hx new file mode 100644 index 00000000000..4e52ebdd9c0 --- /dev/null +++ b/tests/misc/cpp/projects/Issue13001/Main.hx @@ -0,0 +1,20 @@ +class Main { + static function main():Void { + var holder = new NativeCallbackHolder(cpp.Callable.fromStaticFunction(increment)); + if (holder.callback.call(41) != 42) { + throw "Invalid native callback result"; + } + } + + static function increment(value:Int):Int { + return value + 1; + } +} + +class NativeCallbackHolder { + public var callback:cpp.FunctionInt, cpp.abi.Abi>; + + public function new(callback:cpp.FunctionInt, cpp.abi.Abi>) { + this.callback = callback; + } +} diff --git a/tests/misc/cpp/projects/Issue13001/compile.hxml b/tests/misc/cpp/projects/Issue13001/compile.hxml new file mode 100644 index 00000000000..029162d798e --- /dev/null +++ b/tests/misc/cpp/projects/Issue13001/compile.hxml @@ -0,0 +1,3 @@ +-main Main +-D HXCPP_GC_GENERATIONAL +-cpp out