[Issue 23681] New: Generated copy constructors failing to generate
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 8 22:45:54 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23681
Issue ID: 23681
Summary: Generated copy constructors failing to generate
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: minor
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: alphaglosined at gmail.com
Copy constructors are failing to generate and be callable if a field is another
struct that does define a copy constructor.
This is quite frustrating for using reference counted types, resulting in more
boiler plate than required.
DMD32 D Compiler v2.101.0-dirty
```d
void main() {
Depender a, b;
b = a;
}
struct Dependency {
this(ref Dependency other) {
this.tupleof = other.tupleof;
}
~this() {
}
}
struct Depender {
Dependency dependency;
}
```
Error:
buggycopyctr.d(3): Error: generated function
`buggycopyctr.Depender.opAssign(Depender p)` is not callable using argument
types `(Depender)`
buggycopyctr.d(3): generating a copy constructor for `struct Depender`
failed, therefore instances of it are uncopyable
Removing destructor from Dependency makes it compile.
Adding an opAssign that takes Depender by ref also works:
```d
void opAssign(ref Depender other) {
this.tupleof = other.tupleof;
}
```
I suspect this issue is strongly related to another issue with copy
constructors I'm having:
Error: generating an `inout` copy constructor for `struct
sidero.base.logger.FileTarget` failed, therefore instances of it are uncopyable
However I wasn't able to reproduce that error message, but I did come up with
the above so it might be helpful to hunt it down.
--
More information about the Digitalmars-d-bugs
mailing list