[Issue 3175] rejects templated ref return function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 18 10:30:45 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3175


Luther Tychonievich <lat7h at virginia.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lat7h at virginia.edu
           Severity|normal                      |trivial


--- Comment #1 from Luther Tychonievich <lat7h at virginia.edu> 2009-11-18 10:30:44 PST ---
This is only a problem with template parameter deduction:

    ref int foo(int x)(int[x] v) if (x>0) { return v[0]; }

    foo!(2)([1,2]); // works
    foo([1,2]);     // gives "only parameters or foreach..." error message


It can be sidestepped by explicit template declaration:

    template foo(int x) if (x>0) {
        ref int foo(int[x] v) { return v[0]; }
    }

    foo([1,2]);     // works


While obviously not as nice as function template syntax, this workaround is not
difficult to read or write and contains full functionality.


I posit the error message is wrong either way: declarations.c line 908 should
read:
    error("only function return types, parameters, and foreach declarations can
be ref");

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list