diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index c1d0bbc34..4901ea391 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -458,7 +458,7 @@ PYBIND11_NOINLINE inline handle get_object_handle(const void *ptr, const detail: auto &instances = get_internals().registered_instances; auto range = instances.equal_range(ptr); for (auto it = range.first; it != range.second; ++it) { - for (auto vh : values_and_holders(it->second)) { + for (const auto &vh : values_and_holders(it->second)) { if (vh.type == type) return handle((PyObject *) it->second); } diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index d58f04e61..8d36744f2 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -169,7 +169,7 @@ extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, P auto instance = reinterpret_cast(self); // Ensure that the base __init__ function(s) were called - for (auto vh : values_and_holders(instance)) { + for (const auto &vh : values_and_holders(instance)) { if (!vh.holder_constructed()) { PyErr_Format(PyExc_TypeError, "%.200s.__init__() must be called when overriding __init__", vh.type->type->tp_name);