Summary: Function pointers need to be stricter
           Product: D
           Version: 2.040
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from yebblies <> 2010-02-12 05:34:08 PST ---
Currently functions pointers can be implicitly converted despite having
different calling conventions.  If at all possible, function pointers should
require a cast to change calling convention.
In a related problem, it is possible to implicitly convert function pointers
with different argument lists.

The following code compiles but segfaults (Access Violation) on dmd 2.040 /

import std.stdio;

void foo(real f)
    writeln("bar ", f);

void main()
    void function(ubyte[4]) ptr1 = &foo;
    extern(C) void function(long, long) ptr2 = ptr1;

    ptr1([0xFF, 0xFF, 0xFF, 0xFF]);
    ptr2(3, 8);

Function pointers cannot, however, be cast to a pointer with a different return
To solve this problem: Disable all implicit conversions between function
pointers, requiring function parameters, return type, and calling convention to
match for assignment copying.  This prevents accidental conversions and allows
template code to be aware of the correct calling convention.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to