[Issue 1563] New: dynamic cast is not always performed

BCS ao at pathlink.com
Tue Oct 9 19:26:56 PDT 2007


Reply to d-bugmail at puremagic.com,

> http://d.puremagic.com/issues/show_bug.cgi?id=1563
> 
> Summary: dynamic cast is not always performed
> Product: D
> Version: 1.022
> Platform: PC
> OS/Version: Windows
> Status: NEW
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: bugzilla at digitalmars.com
> ReportedBy: davidl at 126.com
> class A{}
> class B:A{}
> class C:B{}
> void main()
> {
> A a = new B;
> C c = cast(C)cast(void*)a;
> c = cast(C)c;
> assert(c is null);  // assertion failure
> c = cast(C)cast(A)cast(void*)c;       // workaround
> assert(c is null);
> }
>


it looks to me like the bug is that "cast(ClassType)voidPt" doesn't check 
the type. I think that assuming that something of type C actually is of type 
C should be allowed. The guards should be at the original assignment.

OTOH that makes things with unions fun.




More information about the Digitalmars-d-bugs mailing list