[Issue 6809] New: IFTI should imply const where inout is present on args, but not on return type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 12 16:32:53 PDT 2011


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

           Summary: IFTI should imply const where inout is present on
                    args, but not on return type
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 2011-10-12 16:32:01 PDT ---
example:

void foo(T)(T v)
{
}

inout(int)* bar(inout(int)* x)
{
    foo(x);
    return x;
}

bug.d(1): Error: inout on parameter means inout must be on return type as well
(if from D1 code, replace with 'ref')
bug.d(1): Error: variable bug.foo!(inout(int)*).foo.v inout variables can only
be declared inside inout functions
bug.d(7): Error: template instance bug.foo!(inout(int)*) error instantiating

It is safe for IFTI to assume all inout parameters are const instead of inout,
since inout implicitly casts to const.

However, inout should still be used where it participates in the return type. 
For example, this currently-valid code should continue to compile:

T foo(T)(T v)
{
    return v;
}

inout(int)* bar(inout(int)* x)
{
    return foo(x);
}

-- 
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