I generally insist that subclasses have it too, when reviewing.
This makes it easy to look at a glance whether the author intended the default operators, without having to manually inspect the inheritance tree to see if C++ is going to implicitly prohibit it.
The Style Guide doesn't list exceptions for this case, which is another argument in favour of always adding it.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
While I appreciate the position, you can still end up hiding bugs - which explicit DISALLOW helps.
A common (slightly unfortunate) pattern is to friend some helper class, which serves as the test base, in order to expose certain members for the test to mutate.
However, doing so also exposes the ability for the derived to make implicit copies of the parent.
DISALLOW_COPY_AND_ASSIGN is certainly not limited in utility to header files. It forces it to be a fast failure when you do something you shouldn't be - and helps to document your expectations.
Readability is important, but part of readability is being able to look at a bit of code and correctly reason about its effects. This is why we encourage documentation such as interfaces being implemented, why annotations like OVERRIDE are useful (beyond the static verification aspect), and arguably, why to document whether or not something is intentionally copyable.
A common (slightly unfortunate) pattern is to friend some helper class, which serves as the test base, in order to expose certain members for the test to mutate.
However, doing so also exposes the ability for the derived to make implicit copies of the parent.
If a parent class uses DISALLOW_COPY_AND_ASSIGN, should/must subclasses use it too?
The Google style guide says that unless your class needs to be copyable, it must have DISALLOW_COPY_AND_ASSIGN. That means child classes, internal classes, unit test classes, and everything else.