Bug 5827 – Invalid implicit cast from "int function() ref" to "int function()"

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-04-10T01:10:00Z
Last change time
2011-05-09T04:43:55Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-04-10T01:10:06Z
The following invalid D code is accepted by DMD: import std.stdio; int a=0; ref int g(){ writeln("called g"); return ++a; } void main(){ int function() f=&g; //this should issue an error! writeln(cast(int)&a); writeln(f()); } Output: -144939256 called g -144939256 (&g is implicitly cast to "int function() ref", after that, the identical calling conventions for "ref int" (int*) and int result in an implicit reinterpret-cast from "ref int" to int.)
Comment #1 by yebblies — 2011-05-09T04:43:55Z
*** This issue has been marked as a duplicate of issue 3797 ***