www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4446] New: Templated function result can't be ref if tiargs are infered w/ value tiarg

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4446

           Summary: Templated function result can't be ref if tiargs are
                    infered w/ value tiarg
           Product: D
           Version: 2.041
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com



---
Templated function (free nor member) cannot return by-ref explicitly (i.e. not
with auto ref) if instantiation arguments are infered and the instantiation
arguments contain at least one value argument.


This does not compile:
--------------------
void main()
{
    S s;
    s.opDispatch!"bar"(42); // fails
}
struct S
{
    ref int opDispatch(string str, T)(T arg)
    {
        return _xyz;
    }
    int _xyz;
}
--------------------
% dmd -o- -c test
test.d(8): Error: variable test.S.str only parameters or foreach declarations
can be ref
--------------------


The error does not occur if the template instantiation arguments are not
infered:
--------------------
void main()
{
    S s;
    s.opDispatch!("bar", int)(42); // fine
}
...
--------------------


Auto ref is fine:
--------------------
void main()
{
    S s;
    s.opDispatch!"bar"(42); // fine
}
struct S
{
    auto ref opDispatch(string str, T)(T arg)
    {
        return _xyz;
    }
    int _xyz;
}
--------------------


This is a workaround for opDispatch:
--------------------
struct S
{
    template opDispatch(string str)
    {
        ref int opDispatch(T)(T arg)
        {
            return _xyz;
        }
    }
    int _xyz;
}
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4446


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



---
*** This issue has been marked as a duplicate of issue 3175 ***

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