Bug 7343 – hole in the type system: inout function call compiles but shouldn't

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-21T17:13:00Z
Last change time
2012-01-22T05:33:18Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2012-01-21T17:13:12Z
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 by k.hara.pg — 2012-01-22T05:33:18Z
This issue was recently fixed in 2.058head, by merging https://github.com/D-Programming-Language/dmd/pull/558 .