Bug 1692 – Abstract class dynamic creation bug

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
druntime
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2007-11-24T11:38:00Z
Last change time
2014-02-24T15:59:54Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
jaroslav.kroft

Comments

Comment #0 by jaroslav.kroft — 2007-11-24T11:38:38Z
Hi, here is some piece of code which most probably doesn't work one expect to. version (Tango) { import tango.io.Console; pragma(lib, "tango-user-dmd"); } else { import std.stdio; } class AbstractError: Error { this (char[] msg = null) { super(msg); } } abstract class Dummy { public { this() { if (!this) { throw new AbstractError(); } } } char[] Value(); } int main(char[][] args) { ClassInfo ci = ClassInfo.find("hello.Dummy"); if (ci) { Object o = ci.create(); if (o) { version (Tango) { Cout(o.toUtf8); } else { writef(o.toString); } } } return 0; } This code would compile without any error, but when you try to run, you will receive AV most probably directly in the constructor. I guess that in this case the call of ClassInfo.create should either return null or throw some kind of error....
Comment #1 by samukha — 2008-11-25T08:06:13Z
*** Bug 2453 has been marked as a duplicate of this bug. ***
Comment #2 by gide — 2009-04-23T05:01:45Z
Added example from Bug 2453. abstract class C { } void main() { auto c = cast(C)C.classinfo.create(); assert(c is null); // should pass or classinfo.create should throw an exception }
Comment #3 by yebblies — 2011-07-01T02:57:29Z
The bug is primarily in druntime, but requires a dmd change to pass more information along. https://github.com/D-Programming-Language/dmd/pull/186 https://github.com/D-Programming-Language/druntime/pull/34
Comment #4 by yebblies — 2011-09-14T05:36:40Z
*** Issue 6667 has been marked as a duplicate of this issue. ***
Comment #5 by bugzilla — 2011-10-13T23:25:02Z