A New Krazy Checker for Methods Returning const refs

Jos van den Oever jvdoever at gmail.com
Sat Apr 14 22:40:49 BST 2007


2007/4/14, Allen Winter <winter at kde.org>:
> Based on a new Library Policy that tronical added today [1],
> I will be installing a new Krazy checker for tonight's run that
> complains about public methods that return const references.
> The check only is run in installed headers for public classes.
>
> tronical suggests that
>  const QList<int> &someProperty() const;
> should be written as:
>  QList<int> someProperty() const;

returning X instead of const X& should only be preferred if it is
cheap to copy the class. This is the case for QList, but not
(necessarily) for std::list. I'd even say that for most classes,
returning const X& is to be preferred over returning X. Checking
against a list of classes that are known to be implicitly shared.

Cheers,
Jos




More information about the kde-core-devel mailing list