irritating opCmp behaviour for TypeInfo

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Thu Jul 20 04:38:31 PDT 2006


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:
> 
> #
> # int x;
> #
> # bool b1 = (typeid(typeof(x)) != typeid(int));
> #
> # TypeInfo t1 = typeid(typeof(x));
> # TypeInfo t2 = typeid(int);
> #
> # bool b2 = (t1 != t2);
> #
> # assert(b1 == b2); // FAILS
> #
> 
> 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



More information about the Digitalmars-d-bugs mailing list