]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle self-assignment in Args::operator=
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 27 Apr 2020 14:52:13 +0000 (16:52 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 27 Apr 2020 14:52:13 +0000 (16:52 +0200)
As suggested by clang-tidy.

src/Args.cpp

index 39cba545d42d7a09d4bc5b453f6edd6715b592b6..7d007f715b447a4df5df780fc840fbddb67da991 100644 (file)
@@ -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;
 }