While debugging a bootstrap problem, I noticed that SmallVector stores
one element in SmallVectorImpl and N - 1 in SmallVector. It also
assumes that all elements are continuous in memory. Does C++ makes any
guaranties about the relative memory position of a base and parent
classes?
I haven't studied it a lot, maybe we can keep N elements in
SmallVector and pass the pointer to SmallVectorImpl constructor?
Hi, in simple-inheritance the base object is always allocated first, and because of the union of double, long long, etc… the first element is aligned, so the others will be contigous. It’s a bit tricky but should work always…
While debugging a bootstrap problem, I noticed that SmallVector stores
one element in SmallVectorImpl and N - 1 in SmallVector. It also
assumes that all elements are continuous in memory. Does C++ makes any
guaranties about the relative memory position of a base and parent
classes?
It isn't guaranteed, but true of every implementation I know of.
I haven't studied it a lot, maybe we can keep N elements in
SmallVector and pass the pointer to SmallVectorImpl constructor?
If this would make SmallVector bigger and slower, then I think we should wait for an implementation that requires it. If it is just a minor internal tweak, plz go for it.
Alignment is probably correct, but since access to the memory is
through a T* but the memory is declared as a char (in GCC) or a union
(elsewhere), I suspect it's technically in violation of the strict
aliasing rules.
Since the SmallVectorImpl constructor sets the 3 pointers, it should
be possible to pass in the begin pointer as well as the size, and
remove the hacks.
Also, the comment the says "Default ctor - Initialize to empty."
should probably be changed, since it's not a default constructor.