[LLVMdev] Removing std::vector from APIs (was Re: Mutating the elements of a ConstantArray)

Chris Lattner clattner at apple.com
Fri May 15 09:58:18 PDT 2009


On May 15, 2009, at 3:50 AM, Jay Foad wrote:

>> 3. Any comments on the patch itself?
>>
>> The one major thing to be aware of is that it isn't safe to use  
>> &V[0] when V
>> is an empty std::vector
>
> Oh dear. That's a bit of a flaw in the plan. I suppose the solution is
> to switch to SmallVector whenever this might be a problem.

As David points out, another solution is to make an inline templated  
iterator version like CallInst::Create has.

>> (though it is safe for smallvector).
>
> DR 464 proposes a new data() method. I'd suggest implementing that in
> SmallVector, instead of relying on the relaxed checking in
> operator[]().
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#464
>
> GNU libstdc++'s vector already has this data() method, but I suppose
> we can't rely on in it being in std::vector in general.

Sure, adding .data() to smallvector would make sense.

>> One minor thing is that StructType::get(NULL, 0) looks somewhat  
>> strange to
>> me.  How about adding a zero-argument version of "get" that returns  
>> the
>> empty struct?  That would allow code to use StructType::get().
>
> OK, I've done this for both StructType and FunctionType.
>
> I'll post some patches on llvm-commits.

Cool, thanks Jay!  I'll be out on vacation for the next week, but  
other people are plenty capable of reviewing the patches.  I'll take a  
look at anything remaining when I return.

-Chris



More information about the llvm-dev mailing list