Bug 8955 – Can't have qualified field with not-qualified constructor/postblit

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-03T05:55:00Z
Last change time
2017-07-17T12:26:11Z
Keywords
rejects-valid
Assigned to
nobody
Creator
verylonglogin.reg
See also
https://issues.dlang.org/show_bug.cgi?id=14838, https://issues.dlang.org/show_bug.cgi?id=17658

Comments

Comment #0 by verylonglogin.reg — 2012-11-03T05:55:14Z
Currently constructor/postblit isn't qualified (see Issue 4338 and Issue 4867). But it's violated for struct members: --- struct S { this(this) { } ~this() { } } struct S2 { S s; } const S globalS; // ok const S2 globalS2; // ok void f() { const S localS; // ok const S2 localS2; // ok } struct S3 // or class, or union { const S s; } // any qualifier causes errors --- Errors for S with postblit only: --- Error: function main.S.__postblit () is not callable using argument types () const --- Errors for S with destructor ony (note generated `opAssign`): --- Error: destructor main.S.~this () is not callable using argument types () const Error: function main.S.opAssign (S p) is not callable using argument types (const(S)) const --- Errors for S with postblit and destructor: --- Error: destructor main.S.~this () is not callable using argument types () const Error: function main.S.__postblit () is not callable using argument types () const --- There is no line numbers in errors because of Issue 8954.
Comment #1 by verylonglogin.reg — 2012-11-03T07:25:18Z
Partial workaround: For const/immutable postblit/dtor: --- struct S { private void myPostblit() { } this(this) inout { (cast(S*) &this).myPostblit(); } private void myDtor() { } ~this() inout // Plese `inout` before `~this()` if Issue 8953 unfixed { (cast(S*) &this).myDtor(); } } struct S_ { const S sc; immutable S si; } --- Note: at least `this(this) inout { }` or `opAssign` is required for dtor For shared dtor: --- struct S { void opAssign(shared S s) shared { this = s; } // required for dtor private void myDtor() { } shared~this() // Plese `inout` before `~this()` if Issue 8953 unfixed { (cast(S*) &this).myDtor(); } } struct S_ { shared S sc; } --- Same for constructor except it doesn't require somebody like dtor.
Comment #2 by jens.k.mueller — 2013-01-09T06:58:53Z
I stumbled over this today. What I don't understand is why/how postblit can be const? I mean if the object is const then I shouldn't be allowed to change it. Because you are copying to something that is const.
Comment #3 by jack — 2017-07-16T19:26:48Z
Raising this to major because not being able to define a shared postblit kills shared completely for user defined types.
Comment #4 by dlang-bugzilla — 2017-07-17T06:48:28Z
(In reply to Jack Stouffer from comment #3) > Raising this to major because not being able to define a shared postblit > kills shared completely for user defined types. Denis' original example works since 2.068.0 (https://github.com/dlang/dmd/pull/4845), so I think it would be better to open a new bug for that.