diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index 23e092e73..f2a752e9d 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -98,8 +98,8 @@ public: explicit func_wrapper(func_handle &&hf) noexcept : hfunc(std::move(hf)) {} Return operator()(Args... args) const { gil_scoped_acquire acq; - object retval(hfunc.f(std::forward(args)...)); - return retval.template cast(); + // casts the returned object as a rvalue to the return type + return object(hfunc.f(std::forward(args)...)).template cast(); } };