On Apr 8, 2013, at 10:18 AM, Serge Pavlov <[email protected]> wrote:
> + // If pointee type is a structure or union of zero size (GCC
> extension),
> + // the subtraction does not make sense.
> + CharUnits ElementSize = Context.getTypeSizeInChars(rpointee);
> + if (ElementSize.isZero() &&
> + (rpointee.getTypePtr()->isStructureType() ||
> + rpointee.getTypePtr()->isUnionType())) {
This is rpointee->isRecordType(), and it's much cheaper to check that
*before* getting the type size.
Also, this is only possible in C, so please add !getLangOpts().CPlusPlus to
your check.
You should also test what happens when you try to subtract pointers of
incomplete or ill-formed type:
struct A;
int test(A *x, A *y) { return (y - x); }
struct B {
void z;
};
int test(B *x, B *y) { return (y - x); }
John.
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits