Bug 2735 – Can't assign ref function to function pointer

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-03-15T11:38:00Z
Last change time
2015-06-09T01:21:08Z
Assigned to
bugzilla
Creator
jlquinn

Comments

Comment #0 by jlquinn — 2009-03-15T11:38:27Z
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()
Comment #1 by jarrett.billingsley — 2009-03-15T12:11:25Z
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
Comment #2 by jlquinn — 2009-03-15T13:11:11Z
(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 :-)
Comment #3 by bugzilla — 2009-03-15T14:41:43Z
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.
Comment #4 by jarrett.billingsley — 2009-03-15T15:23:05Z
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.
Comment #5 by dfj1esp02 — 2009-03-16T05:24:36Z
alias typeof(&c) refintf_t;
Comment #6 by bugzilla — 2009-03-16T20:07:39Z
Please open different issues as different bug reports.