D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6333 - The 'capacity' function is not pure/nothrow/@safe.
Summary: The 'capacity' function is not pure/nothrow/@safe.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P2 trivial
Assignee: No Owner
URL:
Keywords: pull, safe
Depends on:
Blocks:
 
Reported: 2011-07-16 01:59 UTC by kennytm
Modified: 2016-06-08 04:22 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-07-16 01:59:47 UTC
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 Steven Schveighoffer 2011-07-18 07:34:13 UTC
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 Rob Jacques 2012-02-16 14:28:32 UTC
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 Walter Bright 2016-06-07 06:55:48 UTC
The error is now down to:

test2.d(3): Error: safe function 'test2.f6333' cannot call system function 'object.capacity!int.capacity'
Comment 4 Walter Bright 2016-06-07 07:03:47 UTC
https://github.com/dlang/druntime/pull/1588
Comment 5 github-bugzilla 2016-06-08 04:22:30 UTC
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