www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - irritating opCmp behaviour for TypeInfo

reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The following isn't exactly a bug - the documentation doesn't state how
TypeInfo objects are compared - but it is an irritating behaviour:














Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFEvpFeLK5blCcjpWoRAuPhAJ4+NhWzk9wj0PhTl8TG0Frf7u9MsgCgl2BJ
aYNPaKW3fVB71hp64z8z/Dw=
=N9M0
-----END PGP SIGNATURE-----
Jul 19 2006
parent Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
Thomas Kuehne wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 The following isn't exactly a bug - the documentation doesn't state how
 TypeInfo objects are compared - but it is an irritating behaviour:
 












 
 Thomas
 
 
 -----BEGIN PGP SIGNATURE-----
 
 iD8DBQFEvpFeLK5blCcjpWoRAuPhAJ4+NhWzk9wj0PhTl8TG0Frf7u9MsgCgl2BJ
 aYNPaKW3fVB71hp64z8z/Dw=
 =N9M0
 -----END PGP SIGNATURE-----
It's a bug. Consider: writefln( typeid(int) == typeid(int) ); // prints true writefln( typeid(int) != typeid(int) ); // also prints true! INCORRECT Which can't be right, == and != can't give the same results for the same operands. The bug is in the constant folding(evaluation) system: if we the check the asm for that code then 1(true) is generated for both calls. Also, the following code, which are runtime evaluations, work correctly: auto t1 = typeid(int); writefln( t1 == t1 ); // prints 1 writefln( t1 != t1 ); // prints false writefln( t1 == typeid(int) ); // prints 1 writefln( t1 != typeid(int) ); // prints false -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Jul 20 2006