[Issue 7019] implicit constructors are inconsistently allowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 24 07:19:03 PDT 2012


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


Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #9 from Kenji Hara <k.hara.pg at gmail.com> 2012-10-24 07:18:58 PDT ---
(In reply to comment #8)
> 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.

Implemented.
https://github.com/D-Programming-Language/dmd/pull/1213

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