Bug 7511 – attribute inference should work for template functions
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-15T11:17:00Z
Last change time
2013-08-30T14:04:53Z
Keywords
pull
Assigned to
nobody
Creator
timon.gehr
Comments
Comment #0 by timon.gehr — 2012-02-15T11:17:33Z
DMD 2.058:
struct S(T){
T foo(T x){return 2*x;} // this is a pure function for T==int
}
void main()pure{
S!int s;
s.foo(2); // error
}
Error: pure function 'main' cannot call impure function 'foo'
The code should compile. (Turtles all the way down: It should work for methods of nested aggregates of arbitrary nesting level.)
Comment #1 by k.hara.pg — 2012-02-17T07:26:36Z
I think this is an enhancement.
Current attribute inference only works against template function and function literal, not against normal function.
And non-template function insinde templated aggregate is normal function, so the inference does not run for them.
But this is a big issue. Almost ranges in std.range should *inherit* original range's pureness, safety, and nothrow-ness.
To implement it, with current compiler, the only way is to change *all of member functions* in range structs to be tamplated like follows:
struct Retro(R) {
R original;
//auto empty(){ return original.empty; }
auto empty()(){ return original.empty; }
//auto front(){ return original.front; }
auto front()(){ return original.front; }
...
}
...but it may introduce mess and dangerous forward reference, IMHO.