www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9983] New: inout type can not be used as a parameter for structure template

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

           Summary: inout type can not be used as a parameter for
                    structure template
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: maximzms gmail.com



PDT ---
In the following code `inout(int)` is passed to template while it should be
replaced with `int` or `const(int)` depending on the function argument
qualifiers.
--------------------
struct Foo(T)
{
    T* p; // test.d(3)

    this(T* src) { p = src; }
}

auto f(inout int[] a)
{
    return Foo!(inout(int))(a.ptr); // test.d(10)
}

void main() {}
--------------------
test.d(3): Error: variable test.Foo!(inout(int)).Foo.p only parameters or stack
based variables can be inout
test.d(10): Error: template instance test.Foo!(inout(int)) error instantiating
test.d(10): Error: function expected before (), not _error_ of type _error_
--------------------

Workaround:
--------------------
struct Foo(T)
{
    T* p;

    this(T* src) { p = src; }
}

auto f(int[] a)
{
    return Foo!(int)(a.ptr);
}

auto f(in int[] a)
{
    return Foo!(const(int))(a.ptr);
}

void main() {}
--------------------

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