[Issue 271] New: Incorrect constant evaluation of TypeInfo equality comparisons

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 29 11:12:10 PDT 2006


http://d.puremagic.com/issues/show_bug.cgi?id=271

           Summary: Incorrect constant evaluation of TypeInfo equality
                    comparisons
           Product: D
           Version: 0.163
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P1
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: daiphoenix at lycos.com


Consider:

  writefln( typeid(int) is typeid(int) );  // prints true (Correct)
  writefln( typeid(int) !is typeid(int) ); // prints false (Correct)

  writefln( typeid(int) == typeid(Object) ); // prints 0      (Correct)
  writefln( typeid(int) != typeid(Object) ); // prints false! (Correct)

  // prints true (INCORRECT), should be 1, an int:
  writefln( typeid(int) == typeid(int) ); 
  // prints true (INCORRECT), should be false:
  writefln( typeid(int) != typeid(int) ); 

  // prints bool (INCORRECT), should be int 
  writefln( typeid(typeof(typeid(int) == typeid(int))) ); 

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 == and != calls. Also, the
following code, which are all runtime evaluations, work correctly:

  auto ti = typeid(int);
  writefln( ti == ti );          // prints 1     (Correct)
  writefln( ti != ti );          // prints false (Correct)
  writefln( ti == typeid(int) ); // prints 1     (Correct)
  writefln( ti != typeid(int) ); // prints false (Correct)


-- 




More information about the Digitalmars-d-bugs mailing list