Error in assignment to 'this' inside constructor

TommiT tommitissari at hotmail.com
Sat May 11 07:34:39 PDT 2013


I'm trying to assign (or simply bit-copy) over 'this' inside a 
constructor. There's an error when compile-time constructing the 
object. Is this a bug in DMD (2.062) ?

module main;

struct Test
{
     enum Test t = Test(1);
     int v;

     this(int)
     {
         v = 123;
     }

     this(int, int)
     {
         this = t;
     }
}

void main()
{
     Test t1 = Test(11, 22);
     writeln(t1.v); // Prints: 123

     enum t2 = Test(11, 22); // Error:
     // CTFE internal error: unsupported assignment this = 
Test(123)
}


More information about the Digitalmars-d-learn mailing list