December 02, 2019 [Issue 20424] A constructor with a value argument of the same type as being constructed should be an error | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20424 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |razvan.nitu1305@gmail.com --- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> --- This issue is invalid. That is not a copy constructor, it is a normal constructor so there is no threat of entering in infinite recursion. The reason why it works is that the compiler simply blitts the contents of a into the stack of the constructor. I don't see any problem with this. -- |
June 17, 2020 [Issue 20424] A constructor with a value argument of the same type as being constructed should be an error | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20424 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #5 from RazvanN <razvan.nitu1305@gmail.com> --- (In reply to Walter Bright from comment #2) > An object with a copy constructor cannot be blitted into place. (Such is not allowed in C++, either, and such constructors are rejected by the compiler.) > > There is no advantage to doing it anyway over passing by ref. Yes there is. You may want to construct from an rvalue, therefore you cannot use a copy constructor since rvalue references are not yet implemented in the language (there is a switch but it is only half implemented). `this(S)` does exactly that. Of course, it is illegal to have both this(S) and this(ref S). We discussed this extensively in the DIP. -- |
Copyright © 1999-2021 by the D Language Foundation