[LLVMdev] [RFC] Relax the rules on const auto&? (was Re: r203179 - [C++11] Replacing iterators redecls_begin() and redecls_end() ...)
Duncan P. N. Exon Smith
dexonsmith at apple.com
Fri Mar 7 09:31:36 PST 2014
On Mar 7, 2014, at 9:15 AM, David Blaikie <dblaikie at gmail.com> wrote:
> On Fri, Mar 7, 2014 at 8:58 AM, Duncan P. N. Exon Smith
> <dexonsmith at apple.com> wrote:
>> Unless the pointers themselves are changing, the only benefit here is
>> consistency. But ranges of iterators should use const&, since many
>> iterators are expensive to copy.
>
> To clarify, this isn't about copying iterators
You’re right, that was a tangent.
> (iterators are
> generally cheap to copy) but copy the elements being iterated over.
The point (of my tangent) is that some iterators (scc_iterator,
po_iterator, etc.) have non-trivial state, so copies can be expensive.
>> Accidental copies can be a huge headache, since they lead to subtle
>> bugs that are hard to track down (performance implications aside).
>>
>> I still favour applying the rule generally, since consistency matters.
>> But we could text like:
>>
>> Pointer ranges are a common exception.
>>
>> Any other opinions?
>
> If you write the exception as "auto *x" then it's unambiguous and easy
> to still look at "auto x" as being questionable/to-be-avoided.
This is obviously better. Changed in r203254.
More information about the llvm-dev
mailing list