On Wed, Jun 19, 2013 at 8:12 PM, Serge Pavlov <[email protected]> wrote:
>>
>> +      if (!getLangOpts().CPlusPlus) {
>> +        // If pointee type is a structure or union of zero size (GCC 
>> extension),
>> +        // the subtraction does not make sense.
>> +        if (!rpointee->isVoidType() && !rpointee->isFunctionType()) {
>> +          CharUnits ElementSize = Context.getTypeSizeInChars(rpointee);
>> +          if (ElementSize.isZero()) {
>> +            Diag(Loc,diag::warn_sub_ptr_zero_size_types)
>> +              << rpointee.getUnqualifiedType()
>> +              << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
>> +          }
>> +        }
>> +      }

The logic here is "If rpointee is zero-sized, then emit a warning; and
by the way this should never happen in (Objective-)C++ because C++
doesn't have zero-sized types." I don't know the general project
style, but I feel like this would be better expressed by something
like

>        // If pointee type is a structure or union of zero size (GCC 
> extension),
>        // the subtraction does not make sense.
>        if (!rpointee->isVoidType() && !rpointee->isFunctionType()) {
>          CharUnits ElementSize = Context.getTypeSizeInChars(rpointee);
>          if (ElementSize.isZero()) {
>            assert(!getLangOpts().CPlusPlus);
>            Diag(Loc,diag::warn_sub_ptr_zero_size_types)
>              << rpointee.getUnqualifiedType()
>              << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
>          }
>        }

That way, if someone somehow does manage to introduce a zero-sized
type (extension?) into (Objective-?)C++, the symptom would be a
failed-invariant assertion instead of silently skipping the
diagnostic.  Thoughts?

-Arthur
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to