Thread overview
[Issue 6809] New: IFTI should imply const where inout is present on args, but not on return type
Apr 28, 2012
SomeDude
Apr 09, 2013
Kenji Hara
October 12, 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@puremagic.com
        ReportedBy: schveiguy@yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy@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: -------
April 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6809


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #1 from SomeDude <lovelydear@mailmetrash.com> 2012-04-28 02:21:59 PDT ---
Compiles with dmd 2.059 Win32

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 09, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6809


Kenji Hara <k.hara.pg@gmail.com> changed:

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


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2013-04-08 21:17:17 PDT ---
By fixing 7105, it has been changed to valid code.

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