There is no need to use std::move on an r-value (e.g. std::move(gpiod::chip())). Similarly, there is no need to use std::move for returning a local variable as in: T foo() { U local; return std::move(local); } Not only it doesn't help, it actually inhibits named return value optimization. See e.g. https://isocpp.org/blog/2013/02/no-really-moving-a-return-value-is-easy-stackoverflow Signed-off-by: David Kozub <zub@xxxxxxxxxxxxxxxxxx> --- bindings/cxx/chip.cpp | 16 ++++++++-------- bindings/cxx/iter.cpp | 8 ++++---- bindings/cxx/line.cpp | 8 ++++---- bindings/cxx/line_bulk.cpp | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/bindings/cxx/chip.cpp b/bindings/cxx/chip.cpp index 9b825c7..54c85da 100644 --- a/bindings/cxx/chip.cpp +++ b/bindings/cxx/chip.cpp @@ -90,14 +90,14 @@ void chip::reset(void) noexcept { this->throw_if_noref(); - return ::std::move(::std::string(::gpiod_chip_name(this->_m_chip.get()))); + return ::std::string(::gpiod_chip_name(this->_m_chip.get())); } ::std::string chip::label(void) const { this->throw_if_noref(); - return ::std::move(::std::string(::gpiod_chip_label(this->_m_chip.get()))); + return ::std::string(::gpiod_chip_label(this->_m_chip.get())); } unsigned int chip::num_lines(void) const @@ -119,7 +119,7 @@ line chip::get_line(unsigned int offset) const throw ::std::system_error(errno, ::std::system_category(), "error getting GPIO line from chip"); - return ::std::move(line(line_handle, *this)); + return line(line_handle, *this); } line chip::find_line(const ::std::string& name) const @@ -131,7 +131,7 @@ line chip::find_line(const ::std::string& name) const throw ::std::system_error(errno, ::std::system_category(), "error looking up GPIO line by name"); - return ::std::move(handle ? line(handle, *this) : line()); + return handle ? line(handle, *this) : line(); } line_bulk chip::get_lines(const ::std::vector<unsigned int>& offsets) const @@ -141,7 +141,7 @@ line_bulk chip::get_lines(const ::std::vector<unsigned int>& offsets) const for (auto& it: offsets) lines.append(this->get_line(it)); - return ::std::move(lines); + return lines; } line_bulk chip::get_all_lines(void) const @@ -151,7 +151,7 @@ line_bulk chip::get_all_lines(void) const for (unsigned int i = 0; i < this->num_lines(); i++) lines.append(this->get_line(i)); - return ::std::move(lines); + return lines; } line_bulk chip::find_lines(const ::std::vector<::std::string>& names) const @@ -163,13 +163,13 @@ line_bulk chip::find_lines(const ::std::vector<::std::string>& names) const line = this->find_line(it); if (!line) { lines.clear(); - return ::std::move(lines); + return lines; } lines.append(line); } - return ::std::move(lines); + return lines; } bool chip::operator==(const chip& rhs) const noexcept diff --git a/bindings/cxx/iter.cpp b/bindings/cxx/iter.cpp index 8c0b9ba..b1acc8c 100644 --- a/bindings/cxx/iter.cpp +++ b/bindings/cxx/iter.cpp @@ -43,7 +43,7 @@ chip_iter make_chip_iter(void) throw ::std::system_error(errno, ::std::system_category(), "error creating GPIO chip iterator"); - return ::std::move(chip_iter(iter)); + return chip_iter(iter); } bool chip_iter::operator==(const chip_iter& rhs) const noexcept @@ -62,7 +62,7 @@ chip_iter::chip_iter(::gpiod_chip_iter *iter) ::gpiod_chip* first = ::gpiod_chip_iter_next_noclose(this->_m_iter.get()); if (first != nullptr) - this->_m_current = ::std::move(chip(first)); + this->_m_current = chip(first); } chip_iter& chip_iter::operator++(void) @@ -91,7 +91,7 @@ chip_iter begin(chip_iter iter) noexcept chip_iter end(const chip_iter&) noexcept { - return ::std::move(chip_iter()); + return chip_iter(); } line_iter begin(line_iter iter) noexcept @@ -101,7 +101,7 @@ line_iter begin(line_iter iter) noexcept line_iter end(const line_iter&) noexcept { - return ::std::move(line_iter()); + return line_iter(); } line_iter::line_iter(const chip& owner) diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp index 470ed20..989976e 100644 --- a/bindings/cxx/line.cpp +++ b/bindings/cxx/line.cpp @@ -37,7 +37,7 @@ unsigned int line::offset(void) const const char* name = ::gpiod_line_name(this->_m_line); - return ::std::move(name ? ::std::string(name) : ::std::string()); + return name ? ::std::string(name) : ::std::string(); } ::std::string line::consumer(void) const @@ -46,7 +46,7 @@ unsigned int line::offset(void) const const char* consumer = ::gpiod_line_consumer(this->_m_line); - return ::std::move(consumer ? ::std::string(consumer) : ::std::string()); + return consumer ? ::std::string(consumer) : ::std::string(); } int line::direction(void) const noexcept @@ -173,7 +173,7 @@ line_event line::event_read(void) const event.source = *this; - return ::std::move(event); + return event; } int line::event_get_fd(void) const @@ -236,7 +236,7 @@ line find_line(const ::std::string& name) break; } - return ::std::move(ret); + return ret; } } /* namespace gpiod */ diff --git a/bindings/cxx/line_bulk.cpp b/bindings/cxx/line_bulk.cpp index 3006b65..8369930 100644 --- a/bindings/cxx/line_bulk.cpp +++ b/bindings/cxx/line_bulk.cpp @@ -149,7 +149,7 @@ void line_bulk::release(void) const throw ::std::system_error(errno, ::std::system_category(), "error reading GPIO line values"); - return ::std::move(values); + return values; } void line_bulk::set_values(const ::std::vector<int>& values) const @@ -197,7 +197,7 @@ line_bulk line_bulk::event_wait(const ::std::chrono::nanoseconds& timeout) const ret.append(line(event_bulk.lines[i], this->_m_bulk[i].get_chip())); } - return ::std::move(ret); + return ret; } line_bulk::operator bool(void) const noexcept @@ -245,12 +245,12 @@ bool line_bulk::iterator::operator!=(const iterator& rhs) const noexcept line_bulk::iterator line_bulk::begin(void) noexcept { - return ::std::move(line_bulk::iterator(this->_m_bulk.begin())); + return line_bulk::iterator(this->_m_bulk.begin()); } line_bulk::iterator line_bulk::end(void) noexcept { - return ::std::move(line_bulk::iterator(this->_m_bulk.end())); + return line_bulk::iterator(this->_m_bulk.end()); } void line_bulk::throw_if_empty(void) const -- 2.20.1