1038 – explicit class cast breakage in 1.007

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1038 - explicit class cast breakage in 1.007
Summary: explicit class cast breakage in 1.007
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 critical
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2007年03月08日 04:54 UTC by FeepingCreature
Modified: 2014年02月16日 15:25 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2007年03月08日 04:54:53 UTC
Consider the following code:
import std.stdio;
class A { }
class B : A { }
void main() {
 A test=new B;
 writefln("Test is ", test.toString);
 A test_2=cast(A)(new B);
 writefln("Test 2 is ", test_2.toString);
}
What we would expect to see is "test7.B" twice.
However, what we see is "test7.B" and "test7.A", which of course completely breaks polymorphism.
The error doesn't appear on 1.005, so it was introduced either in '006 or '007.
Greetings --downs
Comment 1 Frits van Bommel 2007年03月08日 05:20:14 UTC
Judging by the disassembled code, it appears "cast(A)(new B)"is compiled as if it was "new A", it passes the ClassInfo for A instead of that for B to _d_newclass...
By the way, the same thing happens in GDC[1], so it's most likely an error in the front-end.
[1]: (gdc 0.23, using dmd 1.007), the x86-64 Linux binary from sourceforge.
Comment 2 Thomas Kühne 2007年03月11日 06:20:27 UTC
Added to DStress as
http://dstress.kuehne.cn/run/c/cast_34_A.d
http://dstress.kuehne.cn/run/c/cast_34_B.d 
Comment 3 Thomas Kühne 2007年03月12日 01:23:42 UTC
Fixed in DMD-1.009


AltStyle によって変換されたページ (->オリジナル) /