Struct copy constructor with inout
Nick Treleaven
nick at geany.org
Thu Nov 16 19:51:29 UTC 2023
On Tuesday, 14 November 2023 at 13:58:17 UTC, Paul Backus wrote:
> On Tuesday, 14 November 2023 at 13:41:32 UTC, Steven
> Schveighoffer wrote:
>> ```
>> Error: copy constructor `testinoutctor.S1.this(ref const(S1)
>> s) const` is not callable using argument types `(const(S1))`
>> ```
>>
>> I'm not sure what this means. There shouldn't be a copy being
>> made here, as the thing is already const. I don't understand
>> this error, and it looks like a bug to me.
>
> The error is saying that the copy constructor expects a `const`
> `this` argument, but you're passing a mutable `this` argument.
Thanks for explaining, it's a confusing error.
The error when the constructor is changed to be immutable is:
```
Error: `immutable` method `immutable_ctor.S1.this` is not
callable using a mutable object
```
(I've made a fix to say constructor instead of method for that.)
Now I've made a fix to produce a similar error for const:
https://issues.dlang.org/show_bug.cgi?id=24248
More information about the Digitalmars-d-learn
mailing list