Problem with constant structs, destructors and copy constructors

Max Samukha spambox at d-coding.com
Mon Aug 2 04:27:33 PDT 2010


In the current compiler, the non-constant destructor cannot be called on 
a constant struct object:

struct S
{
     ~this() {}
}


void foo() {
     const S s;
}

Error: destructor test.S.~this () is not callable using argument types ()

This can be worked around by applying 'const' to the destructor. The 
question is: do const/immutable destructors even make sense?

Copy constructors are presently unusable with constant struct objects:

struct S
{
     this(this) {}
}

void bar()
{
     const S s;
     const S s2 = s;
}

Error: function test.S.__cpctor (ref S p) is not callable using argument 
types (const(S)) const

While one can give 'const' attribute to the copy constructor, the hidden 
argument still remains non-constant. The same question: do constant copy 
constructors make sense?

This is a serious problem. Please comment.






More information about the Digitalmars-d mailing list