[webkit-dev] When to use "auto"? (I usually consider it harmful)
ctruta at gmail.com
Fri Jan 3 10:55:07 PST 2014
On Fri, Jan 3, 2014 at 1:11 PM, Alexey Proskuryakov <ap at webkit.org> wrote:
>> auto sourceDescendants = descendantsOfType<HTMLSourceElement >(*this));
> So do we need auto or auto& here? I would know how to answer this
question immediately if it was an explicit type, but I don't know how to
answer it with auto in this particular case.
> One shouldn't need even basic familiarity with style system to see
whether code leaks, introduces refcount thrashing, or copies too much.
Using auto tends to make such mistakes much more opaque.
How about preserving not only the ptrs and refs, but also the
CV-qualifiers, when applicable?
auto* cache = new Cache; // right
auto cache = new Cache; // wrong, should be auto*
Cache* cache = new Cache; // wrong, should be auto*
const ClipboardFormatMap& formatMap = getClipboardMap(); // right
const auto& formatMap = getClipboardMap(); // also right
auto& formatMap = getClipboardMap(); // wrong, missing const
auto formatMap = getClipboardMap(); // wrong, missing const and &
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev