digitalmars.D - Disabling copy constructor in shared structs
- Artur Skawina (26/26) Feb 13 2012 Using "@disable this(this);" in structs marked as "shared" does not appe...
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', like wrong type. not mutable or not an lvalue, usually without even mentioning any line number. Defining a real postblit breaks too; commenting the 'this(this)' out makes the code work again, but i'd like to prevent "auto s2 = s1" from working, as this 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 similar 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? artur [and yes, "this(shared this) shared" etc will compile - but won't prevent the copy (will not be called at all)]
Feb 13 2012