[LLVMbugs] [Bug 12728] New: SmallVector should either support inserting elements from the vector or not

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed May 2 11:35:18 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12728

             Bug #: 12728
           Summary: SmallVector should either support inserting elements
                    from the vector or not
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Support Libraries
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: rjmccall at apple.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


SmallVectorImpl::insert(iterator, const T &) and
SmallVectorImpl::insert(iterator, T&&) currently have code to detect when the
argument is an element of the vector that has just been displaced and, if so,
to adjust the reference to point to the element at its new location.  However,
before this code is reached, the vector may have grown the backing store
(invalidating the reference).  Furthermore, if the iterator is the end of the
vector, insert simply calls push_back, which is also not safe against arguments
within the vector when the vector needs to grow.

(Also, the test to check whether the argument is an element of the vector uses
simple pointer comparison, which actually has undefined behavior if the
argument is not an element of the vector.  The pointers need to be casted to
uintptr_t before comparison.)

We either support insertions that copy elements of the vector or we don't.  My
preference is to not support them, in which case we should document that
discrepancy from the STL.  If we do decide to support them, we should do so
even in cases where the vector must grow to accommodate the new element(s).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list