[Issue 7019] New: implicit constructors are inconsistently allowed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 26 16:10:12 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=7019
Summary: implicit constructors are inconsistently allowed
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: mrmocool at gmx.de
--- Comment #0 from Trass3r <mrmocool at gmx.de> 2011-11-26 16:09:09 PST ---
Yes, I'm aware that alias this makes it possible to allow implicit conversions,
but it can't solve everything, esp. if you need to modify the value before you
'save' it:
import std.stdio;
struct A
{
int store;
this(int a)
{
store = a << 3;
//...
}
}
void main()
{
A a = 5; // this compiles fine
writeln(a.store); // prints 40
// but it doesn't work on function calls
foo(5); // Error: cannot implicitly convert expression (5) of type int to A
}
// nor does it work at global scope or on struct/class fields
A a = 5; // Error: cannot implicitly convert expression (5) of type int to A
void foo(A a) {}
This is horribly and incomprehensibly inconsistent.
btw, if somebody is able to come up with a serious reason why these shouldn't
be allowed in general, I suggest to introduce @implicit.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list