Add more PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL; resolves "unused" warning when compiling test_custom_type_casters.cpp

This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-06-21 01:06:04 -07:00
parent 3a95ae1165
commit 24d450bf74
2 changed files with 16 additions and 3 deletions

View File

@ -125,11 +125,15 @@ private:
"`operator T &()` or `operator const T &()`"); "`operator T &()` or `operator const T &()`");
public: public:
bool load(handle src, bool convert) { return subcaster.load(src, convert); } bool load(handle src, bool convert) {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(type)
return subcaster.load(src, convert);
}
static constexpr auto name = caster_t::name; static constexpr auto name = caster_t::name;
PYBIND11_TYPE_CASTER_SOURCE_FILE_LINE PYBIND11_TYPE_CASTER_SOURCE_FILE_LINE
static handle static handle
cast(const std::reference_wrapper<type> &src, return_value_policy policy, handle parent) { cast(const std::reference_wrapper<type> &src, return_value_policy policy, handle parent) {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(type)
// It is definitely wrong to take ownership of this pointer, so mask that rvp // It is definitely wrong to take ownership of this pointer, so mask that rvp
if (policy == return_value_policy::take_ownership if (policy == return_value_policy::take_ownership
|| policy == return_value_policy::automatic) { || policy == return_value_policy::automatic) {
@ -591,6 +595,7 @@ struct type_caster<CharT, enable_if_t<is_std_char_type<CharT>::value>> {
public: public:
bool load(handle src, bool convert) { bool load(handle src, bool convert) {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(StringType)
if (!src) { if (!src) {
return false; return false;
} }
@ -606,6 +611,7 @@ public:
} }
static handle cast(const CharT *src, return_value_policy policy, handle parent) { static handle cast(const CharT *src, return_value_policy policy, handle parent) {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(StringType)
if (src == nullptr) { if (src == nullptr) {
return pybind11::none().inc_ref(); return pybind11::none().inc_ref();
} }
@ -613,6 +619,7 @@ public:
} }
static handle cast(CharT src, return_value_policy policy, handle parent) { static handle cast(CharT src, return_value_policy policy, handle parent) {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(StringType)
if (std::is_same<char, CharT>::value) { if (std::is_same<char, CharT>::value) {
handle s = PyUnicode_DecodeLatin1((const char *) &src, 1, nullptr); handle s = PyUnicode_DecodeLatin1((const char *) &src, 1, nullptr);
if (!s) { if (!s) {
@ -786,6 +793,7 @@ protected:
return result.release(); return result.release();
} }
// TODO: PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL...?
Tuple<make_caster<Ts>...> subcasters; Tuple<make_caster<Ts>...> subcasters;
}; };
@ -1295,6 +1303,7 @@ tuple make_tuple() {
template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args> template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
tuple make_tuple(Args &&...args_) { tuple make_tuple(Args &&...args_) {
// TODO: PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL...?
constexpr size_t size = sizeof...(Args); constexpr size_t size = sizeof...(Args);
std::array<object, size> args{{reinterpret_steal<object>( std::array<object, size> args{{reinterpret_steal<object>(
detail::make_caster<Args>::cast(std::forward<Args>(args_), policy, nullptr))...}}; detail::make_caster<Args>::cast(std::forward<Args>(args_), policy, nullptr))...}};
@ -1525,6 +1534,7 @@ private:
return std::forward<Func>(f)(cast_op<Args>(std::move(std::get<Is>(argcasters)))...); return std::forward<Func>(f)(cast_op<Args>(std::move(std::get<Is>(argcasters)))...);
} }
// TODO: PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL...?
std::tuple<make_caster<Args>...> argcasters; std::tuple<make_caster<Args>...> argcasters;
}; };

View File

@ -213,8 +213,9 @@ protected:
/* Type casters for the function arguments and return value */ /* Type casters for the function arguments and return value */
using cast_in = argument_loader<Args...>; using cast_in = argument_loader<Args...>;
using cast_out using make_caster_type_out = conditional_t<std::is_void<Return>::value, void_type, Return>;
= make_caster<conditional_t<std::is_void<Return>::value, void_type, Return>>; PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(make_caster_type_out);
using cast_out = make_caster<make_caster_type_out>;
static_assert( static_assert(
expected_num_args<Extra...>( expected_num_args<Extra...>(
@ -1854,6 +1855,7 @@ public:
auto *ptr = new capture{std::forward<Func>(func)}; auto *ptr = new capture{std::forward<Func>(func)};
install_buffer_funcs( install_buffer_funcs(
[](PyObject *obj, void *ptr) -> buffer_info * { [](PyObject *obj, void *ptr) -> buffer_info * {
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(type);
detail::make_caster<type> caster; detail::make_caster<type> caster;
if (!caster.load(obj, false)) { if (!caster.load(obj, false)) {
return nullptr; return nullptr;
@ -2715,6 +2717,7 @@ void implicitly_convertible() {
return nullptr; return nullptr;
} }
set_flag flag_helper(currently_used); set_flag flag_helper(currently_used);
PYBIND11_DETAIL_TYPE_CASTER_ACCESS_TRANSLATION_UNIT_LOCAL(InputType);
if (!detail::make_caster<InputType>().load(obj, false)) { if (!detail::make_caster<InputType>().load(obj, false)) {
return nullptr; return nullptr;
} }