Bug 9653 – Wrong implicit cast allowed with inheritance

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-05T16:53:33Z
Last change time
2024-12-13T18:04:29Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Kenji Hara
Moved to GitHub: dmd#18528 →

Comments

Comment #0 by k.hara.pg — 2013-03-05T16:53:33Z
C1.foo correctly reports error with wrong implicit conversion from TypeInfo to inout(TypeInfo), but C2.foo doesn't. class B { inout(TypeInfo) foo() nothrow pure inout { return null; } } class C1 { /*override*/ inout(TypeInfo) foo() inout { return typeid(Object); // error, correct } } class C2 : B { override inout(TypeInfo) foo() inout { return typeid(Object); // no error, BUG } }
Comment #1 by henning — 2013-07-28T14:14:44Z
Reduced: class C { inout(TypeInfo) foo() pure inout { return typeid(Object); } } The problem is that by using typeid(Object) you can get access to a global class instance (TypeInfo) in a pure function. And the result of pure functions can be casted to be inout. But in this case you didn't create the class instance by yourself. So only self-created TypeInfo-instances should be allowed to get casted. These are hard to detect though.
Comment #2 by robert.schadek — 2024-12-13T18:04:29Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18528 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB