diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index b65d961f35..11b4dfc925 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -814,7 +814,7 @@ template class type_caster_base : public type_caster_generic { using itype = intrinsic_t; public: - static constexpr auto name = _(); + static constexpr auto name_ = _(); type_caster_base() : type_caster_base(typeid(type)) { } explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) { } @@ -917,7 +917,7 @@ template class type_caster> { "std::reference_wrapper caster requires T to have a caster with an `T &` operator"); public: bool load(handle src, bool convert) { return subcaster.load(src, convert); } - static constexpr auto name = caster_t::name; + static constexpr auto name_ = caster_t::name_; static handle cast(const std::reference_wrapper &src, return_value_policy policy, handle parent) { // It is definitely wrong to take ownership of this pointer, so mask that rvp if (policy == return_value_policy::take_ownership || policy == return_value_policy::automatic) @@ -932,7 +932,7 @@ template class type_caster> { protected: \ type value; \ public: \ - static constexpr auto name = py_name; \ + static constexpr auto name_ = py_name; \ template >::value, int> = 0> \ static handle cast(T_ *src, return_value_policy policy, handle parent) { \ if (!src) return none().release(); \ @@ -1350,7 +1350,7 @@ template class Tuple, typename... Ts> class tuple_caster return cast_impl(std::forward(src), policy, parent, indices{}); } - static constexpr auto name = _("Tuple[") + concat(make_caster::name...) + _("]"); + static constexpr auto name_ = _("Tuple[") + concat(make_caster::name_...) + _("]"); template using cast_op_type = type; @@ -1526,10 +1526,10 @@ template struct is_holder_type : template struct is_holder_type> : std::true_type {}; -template struct handle_type_name { static constexpr auto name = _(); }; -template <> struct handle_type_name { static constexpr auto name = _(PYBIND11_BYTES_NAME); }; -template <> struct handle_type_name { static constexpr auto name = _("*args"); }; -template <> struct handle_type_name { static constexpr auto name = _("**kwargs"); }; +template struct handle_type_name { static constexpr auto name_ = _(); }; +template <> struct handle_type_name { static constexpr auto name_ = _(PYBIND11_BYTES_NAME); }; +template <> struct handle_type_name { static constexpr auto name_ = _("*args"); }; +template <> struct handle_type_name { static constexpr auto name_ = _("**kwargs"); }; template struct pyobject_caster { @@ -1547,7 +1547,7 @@ struct pyobject_caster { static handle cast(const handle &src, return_value_policy /* policy */, handle /* parent */) { return src.inc_ref(); } - PYBIND11_TYPE_CASTER(type, handle_type_name::name); + PYBIND11_TYPE_CASTER(type, handle_type_name::name_); }; template @@ -1867,7 +1867,7 @@ class argument_loader { static constexpr bool has_kwargs = kwargs_pos < 0; static constexpr bool has_args = args_pos < 0; - static constexpr auto arg_names = concat(type_descr(make_caster::name)...); + static constexpr auto arg_names = concat(type_descr(make_caster::name_)...); bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index 7a5dd0130d..aa82deb09c 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -45,8 +45,8 @@ extern "C" inline int pybind11_static_set(PyObject *self, PyObject *obj, PyObjec methods are modified to always use the object type instead of a concrete instance. Return value: New reference. */ inline PyTypeObject *make_static_property_type() { - constexpr auto *name = "pybind11_static_property"; - auto name_obj = reinterpret_steal(PYBIND11_FROM_STRING(name)); + constexpr auto name_value = "pybind11_static_property"; + auto name_obj = reinterpret_steal(PYBIND11_FROM_STRING(name_value)); /* Danger zone: from now (and until PyType_Ready), make sure to issue no Python C API calls which could potentially invoke the @@ -62,7 +62,7 @@ inline PyTypeObject *make_static_property_type() { #endif auto type = &heap_type->ht_type; - type->tp_name = name; + type->tp_name = name_value; type->tp_base = type_incref(&PyProperty_Type); type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; type->tp_descr_get = pybind11_static_get; @@ -159,8 +159,8 @@ extern "C" inline PyObject *pybind11_meta_getattro(PyObject *obj, PyObject *name for static properties to function correctly. Users may override this using `py::metaclass`. Return value: New reference. */ inline PyTypeObject* make_default_metaclass() { - constexpr auto *name = "pybind11_type"; - auto name_obj = reinterpret_steal(PYBIND11_FROM_STRING(name)); + constexpr auto name_value = "pybind11_type"; + auto name_obj = reinterpret_steal(PYBIND11_FROM_STRING(name_value)); /* Danger zone: from now (and until PyType_Ready), make sure to issue no Python C API calls which could potentially invoke the @@ -176,7 +176,7 @@ inline PyTypeObject* make_default_metaclass() { #endif auto type = &heap_type->ht_type; - type->tp_name = name; + type->tp_name = name_value; type->tp_base = type_incref(&PyType_Type); type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; @@ -288,14 +288,14 @@ extern "C" inline int pybind11_object_init(PyObject *self, PyObject *, PyObject inline void add_patient(PyObject *nurse, PyObject *patient) { auto &internals = get_internals(); - auto instance = reinterpret_cast(nurse); - instance->has_patients = true; + auto instance_ptr = reinterpret_cast(nurse); + instance_ptr->has_patients = true; Py_INCREF(patient); internals.patients[nurse].push_back(patient); } inline void clear_patients(PyObject *self) { - auto instance = reinterpret_cast(self); + auto instance_ptr = reinterpret_cast(self); auto &internals = get_internals(); auto pos = internals.patients.find(self); assert(pos != internals.patients.end()); @@ -304,7 +304,7 @@ inline void clear_patients(PyObject *self) { // from the unordered_map first. auto patients = std::move(pos->second); internals.patients.erase(pos); - instance->has_patients = false; + instance_ptr->has_patients = false; for (PyObject *&patient : patients) Py_CLEAR(patient); } @@ -312,32 +312,32 @@ inline void clear_patients(PyObject *self) { /// Clears all internal data from the instance and removes it from registered instances in /// preparation for deallocation. inline void clear_instance(PyObject *self) { - auto instance = reinterpret_cast(self); + auto instance_ptr = reinterpret_cast(self); // Deallocate any values/holders, if present: - for (auto &v_h : values_and_holders(instance)) { + for (auto &v_h : values_and_holders(instance_ptr)) { if (v_h) { // We have to deregister before we call dealloc because, for virtual MI types, we still // need to be able to get the parent pointers. - if (v_h.instance_registered() && !deregister_instance(instance, v_h.value_ptr(), v_h.type)) + if (v_h.instance_registered() && !deregister_instance(instance_ptr, v_h.value_ptr(), v_h.type)) pybind11_fail("pybind11_object_dealloc(): Tried to deallocate unregistered instance!"); - if (instance->owned || v_h.holder_constructed()) + if (instance_ptr->owned || v_h.holder_constructed()) v_h.type->dealloc(v_h); } } // Deallocate the value/holder layout internals: - instance->deallocate_layout(); + instance_ptr->deallocate_layout(); - if (instance->weakrefs) + if (instance_ptr->weakrefs) PyObject_ClearWeakRefs(self); PyObject **dict_ptr = _PyObject_GetDictPtr(self); if (dict_ptr) Py_CLEAR(*dict_ptr); - if (instance->has_patients) + if (instance_ptr->has_patients) clear_patients(self); } @@ -362,8 +362,8 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) { needed in order to satisfy Python's requirements for multiple inheritance. Return value: New reference. */ inline PyObject *make_object_base_type(PyTypeObject *metaclass) { - constexpr auto *name = "pybind11_object"; - auto name_obj = reinterpret_steal(PYBIND11_FROM_STRING(name)); + constexpr auto name_value = "pybind11_object"; + auto name_obj = reinterpret_steal(PYBIND11_FROM_STRING(name_value)); /* Danger zone: from now (and until PyType_Ready), make sure to issue no Python C API calls which could potentially invoke the @@ -379,7 +379,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) { #endif auto type = &heap_type->ht_type; - type->tp_name = name; + type->tp_name = name_value; type->tp_base = type_incref(&PyBaseObject_Type); type->tp_basicsize = static_cast(sizeof(instance)); type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; @@ -514,13 +514,13 @@ inline void enable_buffer_protocol(PyHeapTypeObject *heap_type) { /** Create a brand new Python type according to the `type_record` specification. Return value: New reference. */ inline PyObject* make_new_python_type(const type_record &rec) { - auto name = reinterpret_steal(PYBIND11_FROM_STRING(rec.name)); + auto name_obj = reinterpret_steal(PYBIND11_FROM_STRING(rec.name)); - auto qualname = name; + auto qualname = name_obj; if (rec.scope && !PyModule_Check(rec.scope.ptr()) && hasattr(rec.scope, "__qualname__")) { #if PY_MAJOR_VERSION >= 3 qualname = reinterpret_steal( - PyUnicode_FromFormat("%U.%U", rec.scope.attr("__qualname__").ptr(), name.ptr())); + PyUnicode_FromFormat("%U.%U", rec.scope.attr("__qualname__").ptr(), name_obj.ptr())); #else qualname = str(rec.scope.attr("__qualname__").cast() + "." + rec.name); #endif @@ -551,21 +551,22 @@ inline PyObject* make_new_python_type(const type_record &rec) { auto &internals = get_internals(); auto bases = tuple(rec.bases); - auto base = (bases.size() == 0) ? internals.instance_base - : bases[0].ptr(); + auto base_ptr = (bases.size() == 0) ? internals.instance_base + : bases[0].ptr(); /* Danger zone: from now (and until PyType_Ready), make sure to issue no Python C API calls which could potentially invoke the garbage collector (the GC will call type_traverse(), which will in turn find the newly constructed type in an invalid state) */ - auto metaclass = rec.metaclass.ptr() ? (PyTypeObject *) rec.metaclass.ptr() - : internals.default_metaclass; + auto metaclass_ptr = + rec.metaclass.ptr() ? (PyTypeObject *) rec.metaclass.ptr() + : internals.default_metaclass; - auto heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0); + auto heap_type = (PyHeapTypeObject *) metaclass_ptr->tp_alloc(metaclass_ptr, 0); if (!heap_type) pybind11_fail(std::string(rec.name) + ": Unable to create type object!"); - heap_type->ht_name = name.release().ptr(); + heap_type->ht_name = name_obj.release().ptr(); #ifdef PYBIND11_BUILTIN_QUALNAME heap_type->ht_qualname = qualname.inc_ref().ptr(); #endif @@ -573,7 +574,7 @@ inline PyObject* make_new_python_type(const type_record &rec) { auto type = &heap_type->ht_type; type->tp_name = full_name; type->tp_doc = tp_doc; - type->tp_base = type_incref((PyTypeObject *)base); + type->tp_base = type_incref((PyTypeObject *)base_ptr); type->tp_basicsize = static_cast(sizeof(instance)); if (bases.size() > 0) type->tp_bases = bases.release().ptr(); diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index acfe00bdb7..c0df0e22b9 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -24,7 +24,7 @@ class type_caster { template using cast_op_type = value_and_holder &; operator value_and_holder &() { return *value; } - static constexpr auto name = _(); + static constexpr auto name_ = _(); private: value_and_holder *value = nullptr; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index a04d5365a0..4cb18e168e 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -164,7 +164,7 @@ class cpp_function : public function { process_attributes::init(extra..., rec); /* Generate a readable signature describing the function's arguments and return value types */ - static constexpr auto signature = _("(") + cast_in::arg_names + _(") -> ") + cast_out::name; + static constexpr auto signature = _("(") + cast_in::arg_names + _(") -> ") + cast_out::name_; PYBIND11_DESCR_CONSTEXPR auto types = decltype(signature)::types(); /* Register the function with Python from generic (non-templated) code */ @@ -738,15 +738,15 @@ class cpp_function : public function { msg += pybind11::repr(args_[ti]); } if (kwargs_in) { - auto kwargs = reinterpret_borrow(kwargs_in); - if (kwargs.size() > 0) { + auto kwargs_ = reinterpret_borrow(kwargs_in); + if (kwargs_.size() > 0) { if (some_args) msg += "; "; msg += "kwargs: "; bool first = true; - for (auto kwarg : kwargs) { + for (auto kwarg_ : kwargs_) { if (first) first = false; else msg += ", "; - msg += pybind11::str("{}={!r}").format(kwarg.first, kwarg.second); + msg += pybind11::str("{}={!r}").format(kwarg_.first, kwarg_.second); } } }