0

I get a warning from clang-tidy when overriding the move-assignment operator in a subclass and moving the fields of the sub class after invoking the move-assignment operator of the base class.

Example:

class Base{
     ...
     Base& operator=(Base&& other) {...}
};

class Sub : public Base {
     OtherClass n;
     Sub& operator=(Sub&& other) {
         Base::operator=(std::move(other));
         n = std::move(other.n); // <-- Here is the warning
         return *this;
     }
};

The warning I get is:

Clang-Tidy: 'other' used after it was moved

What is the correct way to override the operator?

peter
  • 553
  • 1
  • 5
  • 13

0 Answers0