www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Disabling copy constructor in shared structs

Using " disable this(this);" in structs marked as "shared" does not appear to be
possible; "shared" alone works, just " disable this(this);" works too, but both
together result in compile failures with cryptic error messages about 'this',
wrong type. not mutable or not an lvalue, usually without even mentioning any
number. Defining a real postblit breaks too; commenting the 'this(this)' out
the code work again, but i'd like to prevent "auto s2 = s1" from working, as
is obviously not a good idea for opaque shared structures which should only be
accessible via getter and setters.
Simple example, which gives a different error than the real code, but has a
problem; this program compiles only when one of the lines marked with '*' is
commented out:

shared                  // *
struct S(T) {
   T i;
    disable this(this); // *

auto s1 = S!int(42);
void main() {
   //auto s2 = s1;

Known bug?


[and yes, "this(shared this) shared" etc will compile - but won't prevent the
 (will not be called at all)]
Feb 13 2012