[PATCH] D87326: [ADT] Fix reference invalidation when self referencing a SmallVector
David Blaikie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 17:07:58 PDT 2020
dblaikie added a comment.
> In D87326#2269796 <https://reviews.llvm.org/D87326#2269796>, @MaskRay wrote:
>
>> Yeah, seems that SmallVector::push_back should be fixed to allow `a.push_back(a[0])`. SmallVector::insert has been fixed in rL134554 <https://reviews.llvm.org/rL134554>
>
> Ah, right, sort of a related but maybe slightly different problem - when not resizing the underlying buffer, elements are moved, then the new one is inserted so the reference may've been invalidated. Probably best to handle that in a separate/follow-up commit - any idea if the C++ standard guarantees this for std::vector, for instance? And if so, how does libc++ implement this guarantee?
Ah, I see at the end of rL134554 <https://reviews.llvm.org/rL134554> "Thanks to Howard Hinnant for clarifying the correct behavior, and explaining how std::vector solves this problem." - so I guess it does guarantee it, and implements it in the same way, by testing address/fixing up the address.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87326/new/
https://reviews.llvm.org/D87326
More information about the llvm-commits
mailing list