[Issue 22639] Copy constructors with default arguments not getting called

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 15 12:56:40 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22639

--- Comment #2 from RazvanN <razvan.nitu1305 at gmail.com> ---
What happens here: before https://github.com/dlang/dmd/pull/12132 , the copy
constructor had priority over default construction, however, there were
numerous bug reports which argued that a copy constructor is not actually a
normal constructor and therefore should not disable default initialization. I
implemented what was asked for, but now this PR complains the other way, that
copy constructors should have priority over default initialization.

Now what can be done about this. Well, we could modify the implementation so
that if a copy constructor has additional default parameters than it will
disable default construction, but, honestly, this seems like a hack. Another
solution would be to first try the copy constructors (if there aren't any
regular constructors) and if a match is found, then just go with it, otherwise,
go with default initialization, but this is problematic since it (1)
complicates the implementation and (2) it complicates the spec (before copy
constructors it was simple: you have a constructor => default construction is
disabled).

Personally, I think that if we decided that copy constructors are just
constructors that additionally may be called implicitly by the compiler in some
situations, then we should just stick with that (this means reverting the
aforementioned PR). However, since there are folks that consider that the copy
constructor is not a normal constructor and therefore default initialization
should be affected by their presence, then this bug is invalid.

--


More information about the Digitalmars-d-bugs mailing list