From: Joel Rosdahl Date: Mon, 27 Apr 2020 14:52:13 +0000 (+0200) Subject: Handle self-assignment in Args::operator= X-Git-Tag: v4.0~523 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18556eb69bd89ea6dd55e90b3547e71d42fcd893;p=thirdparty%2Fccache.git Handle self-assignment in Args::operator= As suggested by clang-tidy. --- diff --git a/src/Args.cpp b/src/Args.cpp index 39cba545d..7d007f715 100644 --- a/src/Args.cpp +++ b/src/Args.cpp @@ -129,16 +129,20 @@ Args::from_gcc_atfile(const std::string& filename) Args& Args::operator=(const Args& other) { - m_args = other.m_args; - argv.m_args = &m_args; + if (&other != this) { + m_args = other.m_args; + argv.m_args = &m_args; + } return *this; } Args& Args::operator=(Args&& other) noexcept { - m_args = std::move(other.m_args); - argv.m_args = &m_args; + if (&other != this) { + m_args = std::move(other.m_args); + argv.m_args = &m_args; + } return *this; }