[webkit-dev] When to use "auto"? (I usually consider it harmful)

Sergio Villar Senin svillar at igalia.com
Fri Jan 3 11:03:17 PST 2014


On 03/01/14 19:55, Cosmin Truta wrote:
> On Fri, Jan 3, 2014 at 1:11 PM, Alexey Proskuryakov <ap at webkit.org
> <mailto:ap at webkit.org>> wrote:
>> 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?
> 
> Example 1:
> auto* cache = new Cache; // right
> auto cache = new Cache; // wrong, should be auto*
> Cache* cache = new Cache; // wrong, should be auto*
> 
> Example 2:
> const ClipboardFormatMap& formatMap = getClipboardMap(); // right
> const auto& formatMap = getClipboardMap(); // also right
> auto& formatMap = getClipboardMap(); // wrong, missing const
> auto formatMap = getClipboardMap(); // wrong, missing const and &

IMHO by using auto preserving the qualifiers we gain nothing and lose
the type information.

BR


More information about the webkit-dev mailing list