[Issue 10850] Inout substituted incorrectly for delegates/fptrs in inout function signature

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Sep 13 12:36:58 PDT 2014


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

--- Comment #4 from Sobirari Muhomori <dfj1esp02 at sneakemail.com> ---
(In reply to Sobirari Muhomori from comment #2)
> > should also be substituted for delegates inside the function signature:
> > 
> > inout(int)* delegate(inout(int)*) foo(ref inout(int) x){
> >     inout(int)* bar(inout(int)*) { return &x; }
> >     return &bar;
> > }
> 
> If one wants a really really stupid fix for nested inout functions, then
> inout data outside of the nested function should be treated as const.

An implementation, which should be technically easy is to preprocess the type
of an outer variable at the point of access in nested function and convert its
inout qualifier to const. So &x expression inside `bar` function will have
const(int)* type and will not implicitly convert to inout(int)* return type.

Illustration, why `bar` shouldn't compile:

inout(int)* delegate(inout(int)*) foo(ref inout(int) x){
    inout(int)* bar(inout(int)*) { return &x; }
    immutable int n;
    immutable int* n1 = bar(&n); //ok for bar's signature
    return &bar;
}

--


More information about the Digitalmars-d-bugs mailing list