Bug 17264 – [REG2.073] uniq fails with const elements
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-03-17T19:28:46Z
Last change time
2018-01-05T13:28:40Z
Assigned to
No Owner
Creator
elpenguino+D
Comments
Comment #0 by elpenguino+D — 2017-03-17T19:28:46Z
The fix for issue 16588 causes code like
const(int)[] var = [0, 1, 1, 2];
assert(var.uniq.equal([0,1,2]));
to result in errors like
std\algorithm\iteration.d(4967): Error: cannot modify const expression this._back
std\algorithm\iteration.d(4971): Error: cannot modify const expression last
std\algorithm\iteration.d(4975): Error: cannot modify const expression this._back
Comment #1 by elpenguino+D — 2017-03-18T20:13:05Z
Elements with a disabled default constructor fail similarly.
struct NoDefault {
int i;
@disable this();
this(int x) { i = x; }
}
NoDefault[] var = [NoDefault(0), NoDefault(1), NoDefault(1), NoDefault(2)];
assert(var.uniq.equal([NoDefault(0), NoDefault(1), NoDefault(2)]));
results in
std\algorithm\iteration.d(4912): Error: field _back must be initialized in constructor
Comment #2 by dlang-bugzilla — 2017-05-06T09:41:38Z