r203665 - Use vector<T>::data() to simplify code

Richard Smith richard at metafoo.co.uk
Wed Mar 12 10:54:57 PDT 2014


On Wed, Mar 12, 2014 at 10:32 AM, Arthur O'Dwyer
<arthur.j.odwyer at gmail.com>wrote:

> On Wed, Mar 12, 2014 at 10:17 AM, Jonathan 'Rynn' Sauer
> <jonathan.sauer at gmx.de> wrote:
> > Hello,
> >
> >> +      Args->data(), Args->data() + Args->size(), Diags,
> >
> > Isn't that identical to
> >
> >   &*Args->begin(), &*Args->end()
>
> The old code's organization implied that if Args is empty, then any
> variation on &Args[0], *Args->begin(), etc. has undefined behavior.
> Certainly *Args->begin() does not identify an object. I don't know
> enough C++ to tell you whether &*Args->begin() is necessarily legal or
> not.


It's not. If *Args is empty, then *Args->begin() is applying * to a
non-dereferenceable iterator, which has undefined behavior. *Args->end()
has undefined behavior no matter whether *Args is empty. data() was added
to vector in C++11 to support exactly this sort of thing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140312/7266467e/attachment.html>


More information about the cfe-commits mailing list