[Issue 11722] New: Qualifier-only casts should not invoke opCast
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 10 17:17:32 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11722
Summary: Qualifier-only casts should not invoke opCast
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: k.hara.pg at gmail.com
--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2013-12-10 17:17:25 PST ---
This is a spin-off issue from bug 5747.
D has a cast syntax for modifying just only the type qualifier of the operand.
http://dlang.org/expression#CastExpression
CastExpression:
cast ( Type ) UnaryExpression
cast ( CastQual ) UnaryExpression <--
cast ( ) UnaryExpression <--
However, if the operand is class or struct, and has opCast member function, the
qualifier-cast cast(qual)exp is translated to cast(qual(typeof(exp))exp, then
it will unintendedly invoke opCast. For example, following code wrongly asserts
in C.opCast.
class C
{
T opCast(T)() { assert(0); }
}
void main()
{
C c = new C();
shared C sc = cast(shared)c;
}
I think this is not good behavior in generic code, and should be fixed.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list