digitalmars.D.bugs - [Issue 14155] New: [REG2.066] A defect in DIP29: the return value of
- via Digitalmars-d-bugs (42/44) Feb 09 2015 https://issues.dlang.org/show_bug.cgi?id=14155
https://issues.dlang.org/show_bug.cgi?id=14155
Issue ID: 14155
Summary: [REG2.066] A defect in DIP29: the return value of some
pure functions cannot be unique pointer
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: accepts-invalid, spec
Severity: regression
Priority: P1
Component: DMD
Assignee: nobody puremagic.com
Reporter: k.hara.pg gmail.com
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.
--
Feb 09 2015








via Digitalmars-d-bugs <digitalmars-d-bugs puremagic.com>