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

Burton Radons burton-radons at smocky.com
Sun May 7 10:04:00 PDT 2006


Anders F Björklund wrote:
> Gregor Richards wrote:
> 
>> 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.

The opCmp method in almost all of the TypeInfo are completely inadequate 
for their task; for example, according to DMD "typeid (void *) == typeid 
(char *)"; any chained type (pointers, arrays, delegates, functions) has 
this problem, which would allow for data corruption in unboxing. That's 
why I used "is" instead: it's better to reject an unboxing than to do it 
wrong.

> So I think that Phobos should be changed.

std.boxer should be changed but only after TypeInfo has been fixed. I 
sent Walter a partial fix* for it (which was faster too) shortly after 
writing std.boxer; I don't know why he didn't incorporate it. Walter?

* Delegates and functions cannot be truly fixed until the TypeInfo 
includes parameter information.



More information about the Digitalmars-d mailing list