is the SmallVector implementation standard c++?

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?

Cheers,

[...]

Does C++ makes any
guaranties about the relative memory position of a base and parent
classes?

The C++ standard doesn't make such guarantees. (Particular implementations may.)

  Daveed

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…

2008/8/28 Rafael Espindola <espindola@google.com>

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.

-Chris

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.

Basing all this off a quick peek at
http://llvm.cs.uiuc.edu/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?revision=55181&view=markup

They are inside a continuous sequence of bytes that comprise the complete object.