[LLVMdev] Removing std::vector from APIs (was Re: Mutating the elements of a ConstantArray)
Jay Foad
jay.foad at gmail.com
Fri May 15 03:50:04 PDT 2009
> 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.
I'm a bit concerned that any new &empty[0] problems that are
introduced will go unnoticed. With GNU libstdc++ they aren't diagnosed
unless you build with -D_GLIBCXX_DEBUG (or ENABLE_EXPENSIVE_CHECKS=1).
For now I'm testing with ENABLE_EXPENSIVE_CHECKS=1, and it is indeed
catching lots of errors!
> (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.
> 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.
Thanks,
Jay.
More information about the llvm-dev
mailing list