Copy Constructor DIP and implementation

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Sep 25 03:48:37 UTC 2018


On Monday, September 24, 2018 9:33:19 PM MDT Manu via Digitalmars-d-announce 
wrote:
> On Mon, 24 Sep 2018 at 16:22, Jonathan M Davis via
>
> Digitalmars-d-announce <digitalmars-d-announce at puremagic.com> wrote:
> > On Monday, September 24, 2018 3:20:28 PM MDT Manu via
> > Digitalmars-d-announce>
> > wrote:
> > > copy-ctor is good, @implicit is also good... we want both. Even though
> > > copy-ctor is not strictly dependent on @implicit, allowing it will
> > > satisfy that there's not a breaking change, it it will also
> > > self-justify expansion of @implicit as intended without a separate and
> > > time-consuming fight, which is actually the true value of this DIP!
> >
> > @implicit on copy constructors is outright bad. It would just be a
> > source of bugs. Every time that someone forgets to use it (which plenty
> > of programmers will forget, just like they forget to use @safe, pure,
> > nothrow, etc.), they're going to have a bug in their program.
>
> perhaps a rule where declaring a copy-ctor WITHOUT @explicit emits a
> compile error...?

That would pretty much defeat the whole purpose of why @implicit was added
to the DIP in the first place. It's just that it would turn the feared
silent code breakage into a compiler error. So, I suppose that it would be
an improvement, but it's the sort of thing that would have to go behind a
transitional compiler switch, and as soon as we do that, why have @implicit
on copy constructors at all? It makes far more sense to use a transitional
compiler switch to simply sort out the problem with the potential (but
highly unlikely) silent breakage and not do anything with @implicit with
copy constructors whatsoever. It avoids having to put a useless attribute on
copy constructors forever, and it avoids any potential bugs.

Then we can have a separate DIP that deals with @implicit and non-copy
constructors for implicit construction. And maybe we do ultimately end up
with @implicit on constructors in D. But if @implicit ends up on copy
constructors, at best, it's going to be a language wort, since it adds zero
value there, but as the DIP currently stands, it's going to be a source of
bugs.

- Jonathan M Davis





More information about the Digitalmars-d-announce mailing list