Bug 6333 – The 'capacity' function is not pure/nothrow/@safe.
Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-16T01:59:00Z
Last change time
2016-06-08T04:22:31Z
Keywords
pull, safe
Assigned to
nobody
Creator
kennytm
Comments
Comment #0 by kennytm — 2011-07-16T01:59:47Z
As titled. Probably it is expected, or not.
Test case:
----------------------------------------
pure @safe nothrow int f6333() {
auto x = [1,3];
return x.capacity;
}
----------------------------------------
x.d(3): Error: pure function 'f6333' cannot call impure function 'capacity'
x.d(3): Error: safe function 'f6333' cannot call system function 'capacity'
x.d(3): Error: capacity is not nothrow
x.d(1): Error: function x.f6333 'f6333' is nothrow yet may throw
----------------------------------------
Comment #1 by schveiguy — 2011-07-18T07:34:13Z
I don't know if capacity can be pure. I haven't thought about the implications of making it pure, maybe there is a way. It seems like a reasonable property.
However, it could technically be nothrow. However, it's technically an alias for arr.reserve(0), and reserve could definitely throw.
I'm unsure how to deal with that. Maybe I need to separate the runtime function into two, one that's pure nothrow, the other which might allocate memory.