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

           Summary: hole in the type system: inout function call compiles
                    but shouldn't
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: timon.g...@gmx.ch


--- Comment #0 from timon.g...@gmx.ch 2012-01-21 17:13:12 PST ---
DMD 2.057:

import std.stdio;
inout(int)** qux(inout(int) p, inout(int)** pp){
    return pp;
}
void main(){
    immutable(int) x;
    immutable(int)* y = &x;
    int z;
    *qux(1,&y)=&z; // BOOM.

    writeln(is(typeof(&z)==int*)            &&
            is(typeof( y)==immutable(int)*) &&
            &z is y); // "true"                                                 
}

The code exploits the fact that inout matching does not check sanity, in order
to perform the forbidden immutable(int)** => const(int)** conversion. The code
could be slightly modified such that it performs an int** => const(int)**
conversion instead.

(Ideally, inout would be deduced as immutable in this specific example and the
assignment would cause an error.)

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

Reply via email to