[Issue 1611] New: State-losing implicit conversions are allowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 24 10:16:08 PDT 2007


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

           Summary: State-losing implicit conversions are allowed
           Product: D
           Version: 2.007
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: andrei at metalanguage.com


In the grand tradition of C, many state-losing conversions among integral types
are implicit. This emasculates integral types and allows many bugs go by
unnoticed.

The following program should print nothing:

import std.stdio;
import std.typetuple;

void main()
{
    alias TypeTuple!(byte, ubyte, short, ushort, int, uint, long, ulong,
                     char, wchar, dchar)
        AllIntegrals;
    foreach (T1; AllIntegrals) 
    {
        foreach (T2; AllIntegrals) 
        {
            static if (is(T1 : T2) && T1.sizeof > T2.sizeof) 
                writeln(T1.stringof, " -> ", T2.stringof);
        }
    }
}

It currently prints 45 lines.


-- 



More information about the Digitalmars-d-bugs mailing list