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.
Comment #2 by sandford — 2012-02-16T14:28:32Z
I wrote a patch which address this for capacity and reserve. Here's pull request: https://github.com/D-Programming-Language/druntime/pull/154
Comment #3 by bugzilla — 2016-06-07T06:55:48Z
The error is now down to: test2.d(3): Error: safe function 'test2.f6333' cannot call system function 'object.capacity!int.capacity'
Comment #4 by bugzilla — 2016-06-07T07:03:47Z
Comment #5 by github-bugzilla — 2016-06-08T04:22:30Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/0c87ca709a5386eaebc900ae9aca4ab585e1facc fix Issue 6333 - The 'capacity' function is not pure/nothrow/@safe https://github.com/dlang/druntime/commit/3ac2b3b97347fa444c627d17bbeae0ddc22b01a8 Merge pull request #1588 from WalterBright/fix6333 fix Issue 6333 - The 'capacity' function is not pure/nothrow/@safe