mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 07:10:30 +00:00
Fix warning C26817 on copying in for (auto vh : value_and_holder(...))
(#2382)
* Fix warning C26817: Potentially expensive copy of variable 'vh' in range-for loop. Consider making it a const reference (es.71). * Replace another instance of `for (auto vh : values_and_holders(...))` with `auto vh &` (found by @bstaletic) Co-authored-by: Michael Goulding <Michael.Goulding@microsoft.com> Co-authored-by: Yannick Jadoul <yannick.jadoul@belgacom.net>
This commit is contained in:
parent
2e2de8c87a
commit
fb042d692f
@ -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);
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, P
|
||||
auto instance = reinterpret_cast<detail::instance *>(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);
|
||||
|
Loading…
Reference in New Issue
Block a user