This compiles: struct S { this(S s) {} this(ref S s) {} this(this) {} } Commenting out this(this) {} yields the error message 'struct S may not define both a rvalue constructor and a copy constructor'. This kind of message should be there if all three are present, too.
This issue is invalid. Defining the postblit makes the compiler ignore the copy constructor, so the error goes away.
Well, duh. What I'm saying it's just as wrong to define all three as it is to define two of them, and an error message should be present in both cases. We could perfectly well define that if there's an rvalue constructor and a copy constructor, one of them takes precedence and the other is ignored. Instead, we have an error message. The fact that we allow all three to be defined with no error message is confusing, and leads the programmer to believe there are no errors even though his carefully-crafted copy constructor is ignored.
@RazvanN7 created dlang/dmd pull request #10057 "Fix Issue 19931 - Missing error message when defining postblit, rvalue constructor and copy constructor" fixing this issue: - Fix Issue 19931 - Missing error message when defining postblit, rvalue constructor and copy constructor https://github.com/dlang/dmd/pull/10057
dlang/dmd pull request #10057 "Fix Issue 19931 - Missing error message when defining postblit, rvalue constructor and copy constructor" was merged into master: - 3509d2f017e62e41443ca09f98e071799bd3fe50 by RazvanN7: Fix Issue 19931 - Missing error message when defining postblit, rvalue constructor and copy constructor https://github.com/dlang/dmd/pull/10057