[Issue 7019] implicit constructors are inconsistently allowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 22 08:06:06 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7019


Andrei Alexandrescu <andrei at metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei at metalanguage.com


--- Comment #8 from Andrei Alexandrescu <andrei at metalanguage.com> 2012-10-22 08:05:52 PDT ---
Consider (assuming A has an int-accepting ctor):

A object = A(1);
// or
auto object = A(1);

In here the name of the type being constructed appears in clear, so there's no
chance for a potential confusion. The code currently works, as it should.

Consider:

A object = 1;

Again the type being constructed appears in clear. The code works in a function
but not at top level. It is a bug that it doesn't work at top level, because
the equivalent construct A object = A(1) does.

Now consider: 

void fun(A)  { ... }
fun(1);

In here there's no explicit mention of A in the call, which makes this case
qualitatively different from the ones above. Currently the compiler rejects the
code and I think it does very well so. Implicit conversions on function calls
is unrecommended in the presence of function overloading, and essentially C++
made a mistake about it that it has later partially fixed with the "explicit"
keyword. We won't repeat that mistake.

-- 
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