It's not necessary. Line 5 will work fine if you compare the same object to itself. The only reason I can think of for checking is for performance reasons, but comparing an object to itself is rare so it might not be worth it.
also note that this example is missing a const qualifier, so it will fail to compile when called with a const argument on the left (common error, and one of the motivational examples for the default comparisons proposal, which, by the way, does not specify a self-comparison check)
> for operator= (assignment) it's usually critical.
In modern C++, it is usually not required.
The special case (where a check for self-assignment is required for lvalues) is when we want to optimally reuse existing resources held by the target of the assignment.
The unified assignment operator with non-throwing swap - canonical and exception-safe:
1 2 3 4 5
T& T::operator=(T arg) // copy/move constructor is called to construct arg
{
swap(arg); // resources are exchanged between *this and arg
return *this;
} // destructor of arg is called to release the resources formerly held by *this