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

--- Comment #0 from 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.


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(;
        writefln("Created " ~ ~ " - IsNull: " ~ to!string(MyC is null)
~ " -  Location: " ~ to!string(&MyC) ~ ".");
        Objects ~= MyC;
        writefln("Added to collection.");


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

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to