www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7725] New: Implicit function pointer cast

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7725

           Summary: Implicit function pointer cast
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



void foo1(void function(int) f) {}
void foo2(void function(in int) f) {}
void bar1(int) {}
void bar2(in int) {}
void main() {
    foo1(&bar1); // OK
    foo2(&bar2); // OK
    foo1(&bar2); // Err
    foo2(&bar1); // Err
}



DMD 2.059head gives:

test.d(8): Error: function test.foo1 (void function(int) f) is not callable
using argument types (void function(const(int)))
test.d(8): Error: cannot implicitly convert expression (& bar2) of type void
function(const(int)) to void function(int)
test.d(9): Error: function test.foo2 (void function(const(int)) f) is not
callable using argument types (void function(int))
test.d(9): Error: cannot implicitly convert expression (& bar1) of type void
function(int) to void function(const(int))


I think void function(in int) is a subset of void function(int). So I think
only one of the calls should to give an error, while the other seems better as
safe implicit cast.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7725


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eberhardhoepfner gmx.de



06:51:00 PDT ---
*** Issue 11207 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 10 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7725


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



06:51:09 PDT ---
Another test-case copied from
http://d.puremagic.com/issues/show_bug.cgi?id=11207#c0:


 class A {}
 class B : A {}
 B foo(const A) { return null; }
 void main() {
     A function(const A)     f1 = &foo;  // compiles
     B function(A)           f2 = &foo;  // does not compile
     B function(immutable A) f3 = &foo;  // does not compile
     B function(B)           f4 = &foo;  // does not compile
 }
 
 test.d(6): Error: cannot implicitly convert expression (& foo) of type B
 function(const(A) _param_0) to B function(A)
 test.d(7): Error: cannot implicitly convert expression (& foo) of type B
 function(const(A) _param_0) to B function(immutable(A))
 test.d(8): Error: cannot implicitly convert expression (& foo) of type B
 function(const(A) _param_0) to B function(B)
 
 
 These implicit conversions should be possible. Explicit casting is too
 confusing and dangerous. If you make a mistake, you will end up with serious
 runtime errors.
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 10 2013