[cfe-dev] @encode objc problem

Eli Friedman eli.friedman at gmail.com
Sat Mar 7 13:07:47 PST 2009


On Sat, Mar 7, 2009 at 10:52 AM, Jean-Daniel Dupas
<devlists at shadowlab.org> wrote:
> Some widely used testing framework (SenTestingKit which is part of the
> Xcode distribution for example) use this kind of test
>
> if (@encode(__typeof__(a1)) != @encode(__typeof__(a2))) {
>
> }
>
> Yep, @encoded "returns" a character string, and these strings are
> compared using == (or != ) and not strcmp, and it works quite well
> using GCC because GCC generates only one const string per type.

Nasty.  "Fixed" in r66346; not that we claim to support this, but it
wasn't difficult to change.

> And if the Obj-C ref is not updated to guarantee that the returns
> value can be compared using ==, I think you may also add a warning.

That's definitely not guaranteed, at least at the moment; we can't
guarantee that @encode(X) == @encode(X) in general without giving them
mangled names, which seems like serious overkill.  We could make some
weak guarantee about strings in the same file, but really, they should
be using strcmp.  Please file bug reports with the upstream.

I filed PR3753 on adding a warning.

-Eli



More information about the cfe-dev mailing list