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 ----------------------------------------
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.
I wrote a patch which address this for capacity and reserve. Here's pull request: https://github.com/D-Programming-Language/druntime/pull/154
The error is now down to: test2.d(3): Error: safe function 'test2.f6333' cannot call system function 'object.capacity!int.capacity'
https://github.com/dlang/druntime/pull/1588
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