[llvm] r234963 - Change range-based for-loops to be -Wrange-loop-analysis clean.

Richard Trieu rtrieu at google.com
Wed Apr 15 11:20:04 PDT 2015


On Tue, Apr 14, 2015 at 10:14 PM, Pete Cooper <peter_cooper at apple.com>
wrote:

>
>
> Sent from my iPhone
>
> On Apr 14, 2015, at 8:21 PM, Richard Trieu <rtrieu at google.com> wrote:
>
> > -    for (const auto &MapEntry : VMap) {
>> > +    for (const auto MapEntry : VMap) {
>>
>> What's the deal with this change? Is the type small & trivially
>> copyable & we're suggesting using values instead of references?
>
>
>>
>> VMap does not return a reference, so remove the reference type to
> indicate a copy is always made.
>
> Are there any cases where you'll change something from ref to a value
> because it's 'small and trivially copyable'?
>
> If so, my worry is what happens if I change the type to be a bit larger or
> less trivial to copy. How will I be able to spot the range based for loop
> uses (which now do a copy) and change them back to refs? The problem is
> that changing them back in that way could result in false positives because
> perhaps in some uses I wanted the copy and in others I didn't.
>
> So basically, are we able to reliably detect when to do the reverse
> transformation at a later date, and if not, should we do a transform now
> that is potentially difficult to undo later?
>
> Cheers
> Pete
>

This warning only triggers when a copy is made.  If the reference is bound
to something that is not a copy, then this warning will not be issued.  If
there is a suggestion to go from reference type to non-reference type, then
a copy was already being made.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150415/1ff9421f/attachment.html>


More information about the llvm-commits mailing list