www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19126] New: Compiler removes inout on templated parameter and

https://issues.dlang.org/show_bug.cgi?id=19126

          Issue ID: 19126
           Summary: Compiler removes inout on templated parameter and then
                    complains it's not there
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ali.akhtarzada gmail.com

struct W(T) {
    this(U : T)(auto ref inout(U) val) inout {}
}

auto wrap0(T)(auto ref inout(T) t) {
    return inout W!T();
}

auto wrap1(T)(auto ref inout(T) t) {
    return t;
}

void main() {
    wrap0!int(3); // ok
    wrap0!(const int)(3); // ok
    wrap0!(immutable int)(3); // Error: inout on return means inout must be on
a parameter

    wrap1!int(3); // ok
    wrap1!(const int)(3); // ok
    wrap1!(immutable int)(3); // ok
}

--
Jul 29 2018