Thread overview
[Issue 19871] Copy constructor rejects valid code if default construction is disabled
May 14, 2019
Atila Neves
May 14, 2019
RazvanN
May 14, 2019
Dlang Bot
May 14, 2019
RazvanN
May 14, 2019
Atila Neves
May 14, 2019
RazvanN
May 14, 2019
Dlang Bot
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19871

Atila Neves <atila.neves@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |C++, diagnostic, ice,
                   |                            |ice-on-valid-code

--
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19871

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
The correct behavior here should be an error that you cannot define both the rvalue constructor and the lvalue constructor (copy constructor). For more information, see: https://github.com/dlang/dmd/pull/8688#discussion_r248601249

--
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19871

Dlang Bot <dlang-bot@dlang.rocks> changed:

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

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 created dlang/dmd pull request #9792 "Fix Issue 19871 - Copy constructor rejects valid code if default construction is disabled" fixing this issue:

- Fix Issue 19871 - Copy constructor rejects valid code if default construction is disabled

https://github.com/dlang/dmd/pull/9792

--
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19871

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
*** Issue 19872 has been marked as a duplicate of this issue. ***

--
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19871

--- Comment #4 from Atila Neves <atila.neves@gmail.com> ---
I disagree wholeheartedly that it should be the correct behaviour. I'm pasting the same comment again here so it doesn't get lost.

I missed this discussion originally. The reason one one wants to have:

```d
struct Foo {
    this(ref Foo);
    this(Foo);
}
```

is simple: C++ interop. I made it so that the dpp translations actually enabled D code to call a C++ move constructor by overloading on this.

More importantly, D should be able to do what C++ does without needing rvalue references. So the equivalent of this should be possible:


-----------------------
struct Foo {
    Foo(const Foo& foo); // copy ctor
    Foo(Foo&& foo); // move ctor
};
-----------------------

As you can imagine, any and all types that have been updated post C++11 that had copy constructors now have move constructors. Which I'd declare in D how, exactly?

--
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19871

--- Comment #5 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Atila Neves from comment #4)
> I disagree wholeheartedly that it should be the correct behaviour. I'm pasting the same comment again here so it doesn't get lost.
> 
> I missed this discussion originally. The reason one one wants to have:
> 
> ```d
> struct Foo {
>     this(ref Foo);
>     this(Foo);
> }
> ```
> 
> is simple: C++ interop. I made it so that the dpp translations actually enabled D code to call a C++ move constructor by overloading on this.
> 
> More importantly, D should be able to do what C++ does without needing rvalue references. So the equivalent of this should be possible:
> 
> 
> -----------------------
> struct Foo {
>     Foo(const Foo& foo); // copy ctor
>     Foo(Foo&& foo); // move ctor
> };
> -----------------------
> 
> As you can imagine, any and all types that have been updated post C++11 that had copy constructors now have move constructors. Which I'd declare in D how, exactly?

Well, I think that the idea is that opPostMove (DIP1014) would be the solution.

--
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19871

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #9792 "Fix Issue 19871 - Copy constructor rejects valid code if default construction is disabled" was merged into stable:

- 14ae8a4a4bc39ffc1b1b416ece17e5edfc36f49d by RazvanN7:
  Fix Issue 19871 - Copy constructor rejects valid code if default construction
is disabled

https://github.com/dlang/dmd/pull/9792

--
November 28
https://issues.dlang.org/show_bug.cgi?id=19871

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=23036

--
November 28
https://issues.dlang.org/show_bug.cgi?id=19871

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=19931

--