Bug 2460 – Ref functions can't be template functions.

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-11-18T08:32:00Z
Last change time
2015-06-09T01:20:25Z
Keywords
rejects-valid
Assigned to
nobody
Creator
hskwk

Comments

Comment #0 by hskwk — 2008-11-18T08:32:25Z
Ref functions can't be template functions I guess DMD parser failed to bind `ref' to ref functions if the template is written in function template syntax. It is not serious problem for me. real t; ref real f(S)(S rhs) { size_t tmp; return t; } template g(S) { ref real g(S rhs) { size_t tmp; return t; } } f(1.0); // variable f!(double).f.tmp only parameters or foreach declarations can be ref g(1.0) // no problem
Comment #1 by bugzilla — 2010-03-27T11:27:51Z
Raising importance, since operator overloading is now done with templated functions, and this will become a major pain in the long run.
Comment #2 by repeatedly — 2010-05-24T08:59:21Z
Today, I hit the similar problem. In the latest dmd, above code works but variadic version doesn't works. struct Foo { // works! I use this for workaround template foo(Args...) if (true) { ref Foo foo(Args args) { return this; } } // doesn't work. I want use this!! ref Foo foo(Args...)(Args args) if (true) { return this; } // works! ref Foo foo(Args...)(Args args) { return this; } }
Comment #3 by kennytm — 2011-04-23T09:31:02Z
Looks like this has been fixed. All programs in this page compiles for me. -------- struct Foo { double x, y; ref double get(Args...)(Args args) if (args.length == 4) { return x; } } void main() { Foo f; f.get(4,5,6,7) = 6; assert(f.x == 6); } -------- Can we fix this std.complex bug then? "Some operators, such as opAssign and opOpAssign, should return by ref, but currently don't. This will be implemented as soon as DMD bug 2460 is fixed."
Comment #4 by bugzilla — 2011-04-26T02:40:59Z
Cool! I'll fix std.complex.