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





------- Comment #1 from jarrett.billingsley gmail.com  2009-03-15 12:11 -------
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





------- Comment #2 from jlquinn optonline.net  2009-03-15 13:11 -------
(In reply to comment #1)
 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




------- Comment #3 from bugzilla digitalmars.com  2009-03-15 14:41 -------
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                     |




------- Comment #4 from jarrett.billingsley gmail.com  2009-03-15 15:23 -------
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





------- Comment #5 from maxmo pochta.ru  2009-03-16 05:24 -------
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




------- Comment #6 from bugzilla digitalmars.com  2009-03-16 20:07 -------
Please open different issues as different bug reports.


-- 
Mar 16 2009