typeinfo comparison - 'is' or '=='?

Anders F Björklund afb at algonet.se
Sun May 7 01:44:22 PDT 2006


Gregor Richards wrote:

> I've ran into an issue with typeinfo objects.  It seems that for any 
> type, there should be a static object containing the type info, and 
> furthermore there should only be one in the output program.  My 
> reasoning behind this is that several .d files in phobos/ use 'is' to 
> compare typeinfo's, which implies to me that the 'typeid' operator will 
> return a reference to a statically declared type (since otherwise it 
> could return a different value and you'd get false negatives)

This is a problem for GDC too, when running on old compilers (GCC 3.3) 
that doesn't support once-only linkage and therefore duplicates objects.

http://www.digitalmars.com/d/archives/D/gnu/1594.html

> So my question is: Am I wrong, or is the code in phobos/std/boxer.d and 
> phobos/std/stream.d wrong?

Well, not "wrong" - it is just not portable ? But changing it from 'is'
over to use '==' instead would make it work in more places than it does.

So I think that Phobos should be changed.

--anders



More information about the Digitalmars-d mailing list