[cfe-dev] Comparison of pointers between Objc subclasses
devlists at shadowlab.org
Wed Jul 2 08:16:40 CDT 2008
Le 2 juil. 08 à 12:58, David Chisnall a écrit :
> On 2 Jul 2008, at 00:22, Ted Kremenek wrote:
>> Are pointer type compatibility checks for assignments and conversions
>> being handled in the same way? I can understand why assigning a base
>> type to a derived type is dangerous, but it seems to me that
>> comparisons like these should be legal. I'm only raising this point
>> because the code snippet with the warning involved a comparison, not
>> an assignment.
> Comparisons between ObjC pointers should contain an implicit cast to
> id. I tweaked CodeGen to do this and sent the patch a month or so
> ago, but it wasn't an ideal solution since the problem is really in
> Sema, and it only fixed a few cases where Sema was doing almost the
> right thing but omitting the implicit cast.
Wouldn't this implicit cast prevent the "comparison of distinct
Objective-C types lacks a cast" warning ?
I think gcc emit this warning, because if gcc is right (the two
pointer does not have compatible type), the comparaison will always be
It 's like when you try to compare a negative signed value with an
unsigned value. considere this:
if (-1 == i) ...
In this case, it's safe/legal to compare the two values, and the
condition may even be true, but gcc emit a warning (but it look like
clang does not says anything about it).
Note that I have no idea about what standard says about this case.
I also saw that "clang -pedantic" properly handles the "incompatible
pointer types assigning…" warning.
> Currently there are lots of Objective-C type-system related bugs in
> clang. I hope to have some time in the next few weeks to be able to
> take a look at it. The Objective-C type system doesn't map very
> cleanly to the LLVM type system, unfortunately, and there are lots of
> places where implicit casts need to be emitted but aren't.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2427 bytes
Desc: not available
Url : http://lists.cs.uiuc.edu/pipermail/cfe-dev/attachments/20080702/0e2805bf/attachment-0001.bin
More information about the cfe-dev