<div dir="ltr">Good catch, thank you!<div style>It looks like the check for language is useless, an array of zero length may be found in any of the supported languages.</div><div style><br></div><div style>Thanks,</div><div style>
--Serge</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/6/21 Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Thu, Jun 20, 2013 at 11:32 AM, Arthur O'Dwyer<br>
<<a href="mailto:arthur.j.odwyer@gmail.com">arthur.j.odwyer@gmail.com</a>> wrote:<br>
> On Wed, Jun 19, 2013 at 8:12 PM, Serge Pavlov <<a href="mailto:sepavloff@gmail.com">sepavloff@gmail.com</a>> wrote:<br>
>>><br>
>>> +      if (!getLangOpts().CPlusPlus) {<br>
>>> +        // If pointee type is a structure or union of zero size (GCC extension),<br>
>>> +        // the subtraction does not make sense.<br>
>>> +        if (!rpointee->isVoidType() && !rpointee->isFunctionType()) {<br>
>>> +          CharUnits ElementSize = Context.getTypeSizeInChars(rpointee);<br>
>>> +          if (ElementSize.isZero()) {<br>
>>> +            Diag(Loc,diag::warn_sub_ptr_zero_size_types)<br>
>>> +              << rpointee.getUnqualifiedType()<br>
>>> +              << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();<br>
>>> +          }<br>
>>> +        }<br>
>>> +      }<br>
><br>
> The logic here is "If rpointee is zero-sized, then emit a warning; and<br>
> by the way this should never happen in (Objective-)C++ because C++<br>
> doesn't have zero-sized types." I don't know the general project<br>
> style, but I feel like this would be better expressed by something<br>
> like<br>
><br>
>>        // If pointee type is a structure or union of zero size (GCC extension),<br>
>>        // the subtraction does not make sense.<br>
>>        if (!rpointee->isVoidType() && !rpointee->isFunctionType()) {<br>
>>          CharUnits ElementSize = Context.getTypeSizeInChars(rpointee);<br>
>>          if (ElementSize.isZero()) {<br>
>>            assert(!getLangOpts().CPlusPlus);<br>
>>            Diag(Loc,diag::warn_sub_ptr_zero_size_types)<br>
>>              << rpointee.getUnqualifiedType()<br>
>>              << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();<br>
>>          }<br>
>>        }<br>
><br>
> That way, if someone somehow does manage to introduce a zero-sized<br>
> type (extension?) into (Objective-?)C++, the symptom would be a<br>
> failed-invariant assertion instead of silently skipping the<br>
> diagnostic.  Thoughts?<br>
<br>
</div></div>Thanks for this comment; it turns out that we do actually have<br>
zero-sized types in C++ as an extension already. Here's a C++ testcase<br>
which should trigger the warning:<br>
<br>
typedef int arr[0]; arr *x, *y; int k = x - y;<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Thanks,<br>--Serge<br>
</div>