[Issue 19872] New: Copy constructor: Order of declaration yields different results with rvalue constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 14 14:44:23 UTC 2019


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

          Issue ID: 19872
           Summary: Copy constructor: Order of declaration yields
                    different results with rvalue constructor
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: atila.neves at gmail.com

The code below contains identical struct declarations except for the order of
the constructors in the body. Yet, `Ok` compiles file and `Oops` does not:

----------------------
struct Ok {
    this(ref Ok other);
    this(Ok other);
}


struct Oops {
    this(Oops other);
    this(ref Oops other);
}
----------------------

bug.d(7): Error: struct Oops may not define both a rvalue constructor and a
copy constructor
bug.d(8):        rvalue constructor defined here
bug.d(9):        copy constructor defined here


The order shouldn't make a difference on whether or not the code compiles, but
nearly as importantly: *why* wouldn't one be able to declare both a copy
constructor and an rvalue one? How else would one have both copy and move
semantics?

--


More information about the Digitalmars-d-bugs mailing list