diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 60dfea5b6..c635791fe 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -76,6 +76,11 @@ public: parent); } + template + static handle cast(SrcType *src, return_value_policy policy, handle parent) { + return cast(*src, policy, parent); + } + bool load(handle src, bool convert) { handle native_enum = global_internals_native_enum_type_map_get_item(std::type_index(typeid(EnumType))); diff --git a/tests/test_native_enum.cpp b/tests/test_native_enum.cpp index c919cde2f..0ec6d8554 100644 --- a/tests/test_native_enum.cpp +++ b/tests/test_native_enum.cpp @@ -136,6 +136,15 @@ TEST_SUBMODULE(native_enum, m) { m.def("pass_color", [](color e) { return static_cast(e); }); m.def("return_color", [](int i) { return static_cast(i); }); + m.def("return_color_const_ptr", []() -> const color * { + static const color test_color = color::red; + return &test_color; + }); + m.def("return_color_mutbl_ptr", []() -> color * { + static color test_color = color::green; + return &test_color; + }); + py::native_enum(m, "func_sig_rendering", "enum.Enum").finalize(); m.def( "pass_and_return_func_sig_rendering", diff --git a/tests/test_native_enum.py b/tests/test_native_enum.py index 621a9cfd4..b039747ee 100644 --- a/tests/test_native_enum.py +++ b/tests/test_native_enum.py @@ -153,6 +153,11 @@ def test_return_color_fail(): assert str(excinfo_cast.value) == str(excinfo_direct.value) +def test_return_color_ptr(): + assert m.return_color_const_ptr() == m.color.red + assert m.return_color_mutbl_ptr() == m.color.green + + def test_property_type_hint(): prop = m.class_with_enum.__dict__["nested_value"] assert isinstance(prop, property)