Bug 14155 – [REG2.066] A defect in DIP29: the return value of some pure functions cannot be unique pointer

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-09T09:49:00Z
Last change time
2015-02-21T09:11:14Z
Keywords
accepts-invalid, pull, spec
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2015-02-09T09:49:30Z
DIP29 extended language to support uniqueness. However, the definition contains a problem. http://wiki.dlang.org/DIP29 > CallExpression > if function is pure, then result is the and'ing of all the arguments to the function By that, in some cases the implicit conversion may introduce type system breaking. Example: immutable int g; // runtime initialization, to prevent constfold on all 'g' access static this() { g = 1; } // foo has constant purity, and // its argument may appear in return value. // (== the return value is not isolated from the arguments.) // Any pure function can access immutable global data. // Therefore returning &g by using const(int)* is completely valid. const(int)* foo(const(int)* p) pure { return &g; } void main() { assert(g == 1); // By DIP29 definition, NewExpression is unique pointer. // Therefore the call of foo is deduced to unique and // it's implicitly converted to int*. int* p = foo(new int()); *p = 2; assert(g == 2); // blam! } DIP29 was implemented in 2.066, so it's a regression.
Comment #1 by k.hara.pg — 2015-02-09T13:19:29Z
Related case with NewExpression. immutable int g; static this() { g = 1; } class C { int* p; this(int) immutable pure { p = &g; } } void main() { C c = new immutable C(1); *c.p = 2; assert(g == 2); // blam! }
Comment #2 by k.hara.pg — 2015-02-09T13:33:32Z
Comment #3 by k.hara.pg — 2015-02-09T13:34:38Z
*** Issue 14141 has been marked as a duplicate of this issue. ***
Comment #4 by k.hara.pg — 2015-02-09T13:35:08Z
Comment #5 by github-bugzilla — 2015-02-11T23:23:40Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/e17d26719eb61a30518c997718c14e38bb2912da fix Issue 14155 - A defect in DIP29: the return value of some pure functions cannot be unique pointer https://github.com/D-Programming-Language/dmd/commit/50e1b75c44dca2a47bcded4e639e5775792ae517 Merge pull request #4397 from 9rnsr/fix14155 [REG2.066] Issue 14155 - A defect in DIP29: the return value of some pure functions cannot be unique pointer
Comment #6 by github-bugzilla — 2015-02-21T09:11:14Z
Commits pushed to https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/e17d26719eb61a30518c997718c14e38bb2912da fix Issue 14155 - A defect in DIP29: the return value of some pure functions cannot be unique pointer https://github.com/D-Programming-Language/dmd/commit/50e1b75c44dca2a47bcded4e639e5775792ae517 Merge pull request #4397 from 9rnsr/fix14155