From f99f685160a5956124054c2631f4a14e75cd7727 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 12 Jan 2018 12:37:54 -0400 Subject: [PATCH] MSVC workaround for broken `using detail::_` warning Current MSVC generates totally bizarre errors: error C2884: 'pybind11::detail::_': introduced by using-declaration conflicts with local function 'pybind11::detail::_' which makes no sense (since the supposed "conflict" is the function itself). Work around it by `using namespace detail;` instead (which also lets us drop a bunch of other `detail::` qualifications, so isn't actually a bad thing). --- include/pybind11/numpy.h | 6 +++--- include/pybind11/pybind11.h | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 55bb81698..b1600dc2e 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -946,9 +946,9 @@ struct format_descriptor::value>> { template struct format_descriptor::is_array>> { static std::string format() { - using detail::_; - PYBIND11_DESCR extents = _("(") + detail::array_info::extents() + _(")"); - return extents.text() + format_descriptor>::format(); + using namespace detail; + PYBIND11_DESCR extents = _("(") + array_info::extents() + _(")"); + return extents.text() + format_descriptor>::format(); } }; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 5769509dd..7723d2a8e 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -92,8 +92,9 @@ protected: /// Special internal constructor for functors, lambda functions, etc. template void initialize(Func &&f, Return (*)(Args...), const Extra&... extra) { + using namespace detail; - struct capture { detail::remove_reference_t f; }; + struct capture { remove_reference_t f; }; /* Store the function including any extra state it might have (e.g. a lambda capture object) */ auto rec = make_function_record(); @@ -112,23 +113,23 @@ protected: # pragma GCC diagnostic pop #endif if (!std::is_trivially_destructible::value) - rec->free_data = [](detail::function_record *r) { ((capture *) &r->data)->~capture(); }; + rec->free_data = [](function_record *r) { ((capture *) &r->data)->~capture(); }; } else { rec->data[0] = new capture { std::forward(f) }; - rec->free_data = [](detail::function_record *r) { delete ((capture *) r->data[0]); }; + rec->free_data = [](function_record *r) { delete ((capture *) r->data[0]); }; } /* Type casters for the function arguments and return value */ - using cast_in = detail::argument_loader; - using cast_out = detail::make_caster< - detail::conditional_t::value, detail::void_type, Return> + using cast_in = argument_loader; + using cast_out = make_caster< + conditional_t::value, void_type, Return> >; - static_assert(detail::expected_num_args(sizeof...(Args), cast_in::has_args, cast_in::has_kwargs), + static_assert(expected_num_args(sizeof...(Args), cast_in::has_args, cast_in::has_kwargs), "The number of argument annotations does not match the number of function arguments"); /* Dispatch code which converts function arguments and performs the actual function call */ - rec->impl = [](detail::function_call &call) -> handle { + rec->impl = [](function_call &call) -> handle { cast_in args_converter; /* Try to cast the function arguments into the C++ domain */ @@ -136,7 +137,7 @@ protected: return PYBIND11_TRY_NEXT_OVERLOAD; /* Invoke call policy pre-call hook */ - detail::process_attributes::precall(call); + process_attributes::precall(call); /* Get a pointer to the capture object */ auto data = (sizeof(capture) <= sizeof(call.func.data) @@ -144,26 +145,25 @@ protected: capture *cap = const_cast(reinterpret_cast(data)); /* Override policy for rvalues -- usually to enforce rvp::move on an rvalue */ - const auto policy = detail::return_value_policy_override::policy(call.func.policy); + const auto policy = return_value_policy_override::policy(call.func.policy); /* Function scope guard -- defaults to the compile-to-nothing `void_type` */ - using Guard = detail::extract_guard_t; + using Guard = extract_guard_t; /* Perform the function call */ handle result = cast_out::cast( std::move(args_converter).template call(cap->f), policy, call.parent); /* Invoke call policy post-call hook */ - detail::process_attributes::postcall(call, result); + process_attributes::postcall(call, result); return result; }; /* Process any user-provided function attributes */ - detail::process_attributes::init(extra..., rec); + process_attributes::init(extra..., rec); /* Generate a readable signature describing the function's arguments and return value types */ - using detail::descr; using detail::_; PYBIND11_DESCR signature = _("(") + cast_in::arg_names() + _(") -> ") + cast_out::name(); /* Register the function with Python from generic (non-templated) code */