Clarification on the scope of rule C.83
The company I work for employs a third party static code quality checker. This tool has recently adopted a number of additional checks. One of them is rule C.83. The tool very literally implements the mentioned enforcement "A class without virtual functions should have a swap member function declared."
The consequence of this is that any Plain Old Datatype and non-polymorphic class is flagged if it misses the swap method. The solution advised is to add
class C
{
...
void swap(C &other) noexcept { std::swap(*this, other); }
...
};
in such cases.
I wonder if this was the intention of the rule and if perhaps some context is missing as to when to apply this rule.
std::swap(*this, other);
That's absurd. If a member swap can't be any more efficient than std::swap then I would consider adding one, and decide not to.
If it can be more efficient, then that suggested solution is bad advice.
I agree the enforcement seems too broad without exceptions to say when it's ok to ignore.
The right question should be, what is the definition of value-like type C.83 is based on?