[Issue 20076] [2.087.0] structs won't copy when using alias this and being assigned a const instance of said struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 23 20:27:21 UTC 2019


Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |simen.kjaras at gmail.com

--- Comment #2 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Reduced example:

struct S {
    int* ip;

    this(int* t1) { }

    alias ip this;

unittest {
    const S t3;

    // constructor S.this(int* t1) is not callable using argument types
    S t4 = t3;

As you say, it has to do with the use of classes (or in the above example,
pointers): const(T*) simply cannot be implicitly converted to T* without an
explicit cast - and it shouldn't.

In addition, you have a constructor that looks somewhat like the type of the
alias this, so DMD tries that when a direct conversion fails.

Removing the alias this in the above code results in the message 'cannot
implicitly convert expression t3 of type const(S) to S', which may be more
elucidating. It seems to me the correct behavior would be for DMD to print both
error messages, probably with a hint that alias this is involved in one of the

In a way, alias this is like an overload, and the error messages should reflect


More information about the Digitalmars-d-bugs mailing list