[cfe-dev] "Mutable base class": Operator to base class "will never be used"

Sebastian Redl sebastian.redl at getdesigned.at
Tue Dec 21 09:44:10 PST 2010


On 21.12.2010, at 14:45, Gustaf Räntilä wrote:

> Is there some part of the language saying that an operator to a
> reference of a class which happens to be a base class, is not valid
> (or rather valid but "not used")?

No, but the derived-to-base conversion takes precedence over user-defined conversions. The warning exists because a user-defined conversion from derived to base will never be used under normal circumstances, but the derived-to-base conversion will make code that appears to use it compile, which might not be what the programmer expects.

In your special case, though, I think Clang is wrong. There is no derived-to-base conversion that adds drops const, and const Derived isn't reference-compatible with non-const Base either, so those code paths shouldn't be taken.

Sebastian





More information about the cfe-dev mailing list