diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index d45b49c52e..07a56e71f7 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1243,8 +1243,8 @@ struct arg_v : arg { private: template arg_v(arg &&base, T &&x, const char *descr = nullptr) - : arg(base), value(reinterpret_steal( - detail::make_caster::cast(x, return_value_policy::automatic, {}))), + : arg(base), value(reinterpret_steal(detail::make_caster::cast( + std::forward(x), return_value_policy::automatic, {}))), descr(descr) #if !defined(NDEBUG) , @@ -1491,7 +1491,7 @@ class unpacking_collector { type_id()); #endif } - args_list.append(o); + args_list.append(std::move(o)); } void process(list &args_list, detail::args_proxy ap) { diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 7624c9fbf4..d45fe42803 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -640,9 +640,9 @@ class dtype : public object { list names, formats, offsets; for (auto &descr : field_descriptors) { - names.append(descr.name); - formats.append(descr.format); - offsets.append(descr.offset); + names.append(std::move(descr.name)); + formats.append(std::move(descr.format)); + offsets.append(std::move(descr.offset)); } return dtype(std::move(names), std::move(formats), std::move(offsets), itemsize); } diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 18cd715805..ba0fda0a8c 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -268,10 +268,7 @@ class object : public handle { /// Copy constructor; always increases the reference count object(const object &o) : handle(o) { inc_ref(); } /// Move constructor; steals the object from ``other`` and preserves its reference count - object(object &&other) noexcept { - m_ptr = other.m_ptr; - other.m_ptr = nullptr; - } + object(object &&other) noexcept : handle(other) { other.m_ptr = nullptr; } /// Destructor; automatically calls `handle::dec_ref()` ~object() { dec_ref(); } @@ -1519,8 +1516,8 @@ class weakref : public object { class slice : public object { public: PYBIND11_OBJECT_DEFAULT(slice, object, PySlice_Check) - slice(handle start, handle stop, handle step) { - m_ptr = PySlice_New(start.ptr(), stop.ptr(), step.ptr()); + slice(handle start, handle stop, handle step) + : object(PySlice_New(start.ptr(), stop.ptr(), step.ptr()), stolen_t{}) { if (!m_ptr) { pybind11_fail("Could not allocate slice object!"); } diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 3d1ca7ac23..51b57a92ba 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -79,7 +79,7 @@ struct set_caster { for (auto &&value : src) { auto value_ = reinterpret_steal( key_conv::cast(forward_like(value), policy, parent)); - if (!value_ || !s.add(value_)) { + if (!value_ || !s.add(std::move(value_))) { return handle(); } }