September 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6667

           Summary: Object.factory creates instance of abstract classes.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: opantm+spam@gmail.com


--- Comment #0 from opantm+spam@gmail.com 2011-09-14 04:55:22 PDT ---
Object.factroy successfully creates an invalid instance when used for an abstract class. There is no way to distinguish that the instance is invalid, as it is not null. It may be assigned, but upon first access it will result in a segfault. This also means that (AFAIK), short of looking at the vtbl, you have no way of knowing if a class is abstract using Typeinfo. Object.factory is supposed to return null when errors occur. Tested on Windows 7 64-bit (compiled as 32-bit) and Linux 64-bit.

Example:

import std.stdio;
import std.traits;
import std.conv;

abstract class C {
        string AbstractMethod();
}

C[] Objects;

void main() {
        TypeInfo_Class ti = typeid(C);
        C MyC = cast(C)Object.factory(ti.name);
        writefln("Created " ~ ti.name ~ " - IsNull: " ~ to!string(MyC is null)
~ " -  Location: " ~ to!string(&MyC) ~ ".");
        Objects ~= MyC;
        writefln("Added to collection.");
        writefln(Objects[0].AbstractMethod());
}


Output:

Created temptest.C - IsNull: false -  Location: 7FFF15772900.
Added to collection.
Segmentation fault

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6667


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies@gmail.com
         Resolution|                            |DUPLICATE


--- Comment #1 from yebblies <yebblies@gmail.com> 2011-09-14 22:36:40 EST ---
*** This issue has been marked as a duplicate of issue 1692 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------