[llvm] r178166 - Avoid undefined behavior from passing a std::vector's own contents

Dan Gohman dan433584 at gmail.com
Thu Mar 28 17:16:02 PDT 2013


On Wed, Mar 27, 2013 at 1:47 PM, Howard Hinnant <hhinnant at apple.com> wrote:

> On Mar 27, 2013, at 4:34 PM, Dan Gohman <dan433584 at gmail.com> wrote:
>
> >
> >
> > On Wed, Mar 27, 2013 at 12:16 PM, Howard Hinnant <hhinnant at apple.com>
> wrote:
> > On Mar 27, 2013, at 2:44 PM, Dan Gohman <dan433584 at gmail.com> wrote:
> >
> > > Author: djg
> > > Date: Wed Mar 27 13:44:56 2013
> > > New Revision: 178166
> > >
> > > URL: http://llvm.org/viewvc/llvm-project?rev=178166&view=rev
> > > Log:
> > > Avoid undefined behavior from passing a std::vector's own contents
> > > in as an argument to push_back.
> >
> > The original code is not undefined behavior.
> >
> > My interpretation was that the push_back could cause reallocation which
> could invalidate the reference to the old element before it is read. Is
> there a guarantee that this won't happen?
>
> There is not an allowance for the vendor to let it happen.  Such an
> allowance would look like the one for insert(p, i, j):
>
> > pre: i and j are not iterators into a.
>

Makes sense. I've now reverted the original patch. Thanks!

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130328/d8daa11c/attachment.html>


More information about the llvm-commits mailing list