Bug 10012 – [2.063 beta] pure constructors taking POD structs should be allowed for shared/immutable construction

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-30T02:04:08Z
Last change time
2024-12-13T18:06:36Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Sönke Ludwig
Moved to GitHub: dmd#18574 →

Comments

Comment #0 by sludwig — 2013-04-30T02:04:08Z
The following snippet errors out: --- struct S { } class Test2 { this(S) pure {} } void main() { auto test2 = new shared Test2(S()); auto test3 = new immutable Test2/(S()); } --- test_shared.d(7): Error: mutable method test_shared.Test2.this is not callable u sing a immutable object test_shared.d(7): Error: incompatible types for ((new immutable(Test2)) / (S())) : 'immutable(Test2)' and 'S' However, since any instance of S is an independent copy, the resulting object is still unique and thus should be liable for immutable or shared object construction. Also, in addition to POD types, types containing only immutable references should be allowed. Finally, shared references can also be allowed when constructing a shared object, but this is a different kind of "unique" or "isolated" concept - I call it "weakly isolated" in my library implementation [1] following the "weakly pure" nomenclature - so this may need some bigger changes. [1] https://github.com/rejectedsoftware/vibe.d/blob/6c9efa2fdcef1797c84e58483410f262a2a82d67/source/vibe/core/concurrency.d#L958
Comment #1 by k.hara.pg — 2013-04-30T02:13:44Z
(In reply to comment #0) > auto test3 = new immutable Test2 / (S()); // unnecessary '/' auto test3 = new immutable Test2(S()); After the fix, the code would work.
Comment #2 by sludwig — 2013-04-30T02:24:01Z
Sorry, I was blind while preparing the test case. This is the correct one: --- struct S { string str; } class Test { S _s; this(S s) pure { _s = s; } } void main() { auto test2 = new shared Test(S()); auto test3 = new immutable Test(S()); } --- So POD indeed works right, but immutable (and shared) references are seemingly disallowed.
Comment #3 by k.hara.pg — 2013-05-04T00:43:03Z
(In reply to comment #2) > Sorry, I was blind while preparing the test case. This is the correct one: > > --- > struct S { string str; } > class Test { S _s; this(S s) pure { _s = s; } } > > void main() > { > auto test2 = new shared Test(S()); > auto test3 = new immutable Test(S()); > } > --- > > So POD indeed works right, but immutable (and shared) references are seemingly > disallowed. This is current dmd implementation limitation. In complex cases dmd cannot detect that the constructor generates unique object.
Comment #4 by robert.schadek — 2024-12-13T18:06:36Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18574 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB