www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2735] New: Can't assign ref function to function pointer

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

           Summary: Can't assign ref function to function pointer
           Product: D
           Version: 2.025
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jlquinn optonline.net


ref int c() { static int a=2; return a; }
int function() d = &c;

fails to compile:

jlquinn naga:~/d$ ~/dmd/linux/bin/dmd -v  -c decl1.d 
parse     decl1
semantic  decl1
import    object       
(/home/jlquinn/dmd/linux/bin/../../src/druntime/import/object.di)
semantic2 decl1
decl1.d(2): Error: cannot implicitly convert expression (& c) of type int
function() ref to int function()


-- 
Mar 15 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2735






I suppose it should be mentioned that it's not possible to declare a ref
function pointer, or else this would be a no-brainer:

ref int c() { static int a=2; return a; }
ref int function() d = &c; // line 8

foo.d(8): variable foo.d only parameters or foreach declarations can be ref

Type inference, however, is able to figure it out:

ref int c() { static int a=2; return a; }
auto d = &c; // whee


-- 
Mar 15 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2735







 I suppose it should be mentioned that it's not possible to declare a ref
 function pointer, or else this would be a no-brainer:
 
 ref int c() { static int a=2; return a; }
 ref int function() d = &c; // line 8
Oops, yes, I meant to write that :-) --
Mar 15 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2735


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





The error message is correct, as a function that returns a reference is not the
same type as a function that does not return a reference.


-- 
Mar 15 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2735


jarrett.billingsley gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |





Then I suppose you didn't see my or Jerry's followup comments?  It's not
possible to declare a ref function pointer.  It's possible to infer it, but not
declare one.


-- 
Mar 15 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2735






alias typeof(&c) refintf_t;


-- 
Mar 16 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2735


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID





Please open different issues as different bug reports.


-- 
Mar 16 2009