D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7343 - hole in the type system: inout function call compiles but shouldn't
Summary: hole in the type system: inout function call compiles but shouldn't
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2012-01-21 17:13 UTC by timon.gehr
Modified: 2012-01-22 05:33 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2012-01-21 17:13:12 UTC
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.)
Comment 1 Kenji Hara 2012-01-22 05:33:18 UTC
This issue was recently fixed in 2.058head, by merging https://github.com/D-Programming-Language/dmd/pull/558 .