http://d.puremagic.com/issues/show_bug.cgi?id=6197
Summary: std.traits.isImplicitlyConvertible returns some wrong
results.
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Kenji Hara <[email protected]> 2011-06-23 04:01:22 PDT ---
pragma(msg, implicitlyConverts!(const(uint), ubyte));
should print 'false', but 'true'.
Cause of this bug:
Current implementation is here:
template isImplicitlyConvertible(From, To)
{
enum bool isImplicitlyConvertible = is(typeof({
void fun(To) {}
From v;
fun(f);
}()));
}
When From=const(uint) and To=ubyte, it is rewites as
enum bool isImplicitlyConvertible = is(typeof({
void fun(ubyte) {}
const(uint) v;
fun(f);
}()));
and function argument v is *optimized* to its initial value 0u and matches to
parameter type ubyte by literal conversion.
How to fix:
The variables its initializers are not visible does not cause optimization.
So rewrite as:
enum bool isImplicitlyConvertible = is(typeof({
void fun(ref From v){
void gun(To) {}
gun(v);
}
}()));
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------