[Issue 14155] New: [REG2.066] A defect in DIP29: the return value of some pure functions cannot be unique pointer
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Feb 9 01:49:30 PST 2015
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 at puremagic.com
Reporter: k.hara.pg at 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.
--
More information about the Digitalmars-d-bugs
mailing list