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.
Comment #2 by timon.gehr — 2012-02-17T07:46:20Z
Walter stated that this is indeed how it is supposed to work: http://forum.dlang.org/thread/[email protected]?page=3#post-jhjpfp:2419hg:242:40digitalmars.com If it is an enhancement, then it is a high-priority one.
Comment #3 by timon.gehr — 2012-02-25T07:26:51Z
This should probably not be done for virtual template class member functions.
Comment #4 by k.hara.pg — 2013-02-18T05:41:38Z
In 2.062, required blocker pull requests were all merged. Therefore, implementing it was easier than expected. https://github.com/D-Programming-Language/dmd/pull/1676 (In reply to comment #3) > This should probably not be done for virtual template class member functions. I think it should work, at least in following case. https://github.com/D-Programming-Language/dmd/pull/1676/files#L1R76
Comment #5 by github-bugzilla — 2013-02-21T22:50:41Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/67fbf5753e9d4a276c354e952ed2f888efcb714c fix Issue 7511 - attribute inference does not work for methods of templated aggregates https://github.com/D-Programming-Language/dmd/commit/20d68fdcb4faad2e522c6d33396f79810626d1f4 Merge pull request #1676 from 9rnsr/fix7511 [enh] Issue 7511 - attribute inference does not work for methods of templated aggregates
Comment #6 by hsteoh — 2013-08-30T14:04:53Z
This fix introduced regression issue #10425