OSDN Git Service

Fix a subtle issue in SmallVector. The following code did not work as expected:
authorOwen Anderson <resistor@mac.com>
Wed, 6 Jul 2011 22:36:59 +0000 (22:36 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 6 Jul 2011 22:36:59 +0000 (22:36 +0000)
commit9cbd7afb76f20ce874464c238764c54f86b3ce3b
tree7acc01733408ee1b1164841128edad753982669e
parent4fd3c5957e6a272b60d6446e745136187d07f812
Fix a subtle issue in SmallVector.  The following code did not work as expected:
  vec.insert(vec.begin(), vec[3]);
The issue was that vec[3] returns a reference into the vector, which is invalidated when insert() memmove's the elements down to make space.  The method needs to specifically detect and handle this case to correctly match std::vector's semantics.

Thanks to Howard Hinnant for clarifying the correct behavior, and explaining how std::vector solves this problem.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134554 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/SmallVector.h
unittests/ADT/SmallVectorTest.cpp