[webkit-dev] [webkit-reviewers] usage of auto

Geoffrey Garen ggaren at apple.com
Thu Jan 12 10:42:33 PST 2017


>> My take-away from this discussion so far is that there is actually very little consensus on usage of auto, which means there’s probably very little room for actual style guideline rules.
>> 
>> I think there are two very limited rules that are probably not objectionable to anybody.
>> 
>> 1 - If you are using auto for a raw pointer type, you should use auto*
>> 2 - If you are using auto in a range-based for loop for values that aren’t pointers, you should use (const) auto&
> 
> In some cases you need a copy for the code to be correct. I understand why & is often better for performance but there is a significant and dangerous behavioral difference.
> 
> I agree with encouraging people to use auto& because it's usually ok, but I disagree with mandating it because it's sometimes wrong. 

Seems like we could still have a style guideline in favor of these styles.

Style guidelines are always recommendations, which are of course not followed if they produce incorrect code. For example, it is S_OK to violate our camel case guidelines when interfacing with COM APIs.

I think Darin would also suggest:

1.5 - If you are using auto in a range-based for loop for values that are scalars, you should use auto.

Geoff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20170112/ec0d850e/attachment.html>


More information about the webkit-dev mailing list