[Issue 22614] Wrong copy constructor is called depending on context

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 14 16:14:01 UTC 2022


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

timon.gehr at gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr at gmx.ch

--- Comment #2 from timon.gehr at gmx.ch ---
(In reply to RazvanN from comment #1)
> It seems that for some reason annotating with @safe the unittest enables the
> compiler to infer attributes for the nested struct members. This has the
> result of inferring pure for the copy constructors and therefore the
> immutable constructor becomes a unique constructor (which means it can be
> implicitly convertible to mutable).

In general, unique `immutable` values _cannot_ convert to mutable. Therefore, I
do not understand why the behavior would change here. The struct is convertible
to mutable because there are no mutable indirections, it should not matter
whether or not the copy constructors are pure.

> Next, the compiler thinks that the
> unique copy constructor is better than const copy constructor.
> 
> I think that the fundamental problem here is that @safe enables attribute
> inference. I haven't seen this anywhere explicitly stated in the spec.
> ...

That's a problem, but clearly the code should work even if annotated `pure`, so
it does not seem like this is the _fundamental_ issue.

> The unique conversion rules are another black box for me.

Unique values should be able to implicitly convert to `immutable`, but that's
it.

--


More information about the Digitalmars-d-bugs mailing list