www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7343] New: hole in the type system: inout function call compiles but shouldn't

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch



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: -------
Jan 21 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7343


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

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



This issue was recently fixed in 2.058head, by merging
https://github.com/D-Programming-Language/dmd/pull/558 .

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