D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3650 - functions are considered pointers
Summary: functions are considered pointers
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-12-26 09:45 UTC by nfxjfg
Modified: 2014-04-18 09:12 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description nfxjfg 2009-12-26 09:45:34 UTC
First off, this bug report is for dmd 1.053, not 1.051; but bugzilla let's me only select up to 1.051.

The following code outputs "what (void())()", which shows that function pointers are matched with is(T T2 : T2*). I think this shouldn't be the case: although technically function pointers really are pointers, D doesn't declare them using the pointer syntax, doesn't allow them to be dereferenced, and they don't point to any type.

If this bug is fixed, functions won't match with is(T T2 : T2*) anymore.

If this is just an anti-feature and not a bug, please mark this bug report as "invalid".

struct X {
    void function() foo;
}

void moo(T)() {
    static if (is(T T2 : T2*)) {
        pragma(msg, "what "~T2.stringof);
    }
}

void main() {
    X x;
    foreach (int index, z; x.tupleof) {
        moo!(typeof(z));
    }
}
Comment 1 Stewart Gordon 2009-12-26 11:11:08 UTC
I've always been under the impression that immediate function types aren't meant to exist in D, which would mean that the is expression should fail.

But there does seem to be some confusion over it.  And in any case, the stringof does seem wrong.
Comment 2 Stewart Gordon 2010-01-02 16:44:03 UTC
You stated that it's 1.053 you found it in, but inadvertently set it to 1.054 when the version list was updated.

But I've just found that I'm still on 1.051 and the bug shows in it, so reverting per policy.
Comment 3 nfxjfg 2010-01-02 16:51:16 UTC
I guess the bug exists since the early days of dmd.
Just to clarify it: it also exists in 1.054. (That's why I changed it; sorry for the confusion, won't do again.)

A statement from Walter whether this is an anti-feature or a bug would be nice. (And in general, there are far too many bug reports with unknown status, that remain uncommented.)
Comment 4 nfxjfg 2010-01-19 12:30:59 UTC
PS: as far as is() is concerned, functions should just work like delegates. Any difference should be considered as bug.

Also, if this happens not to be a bug, please mark it as "enhancement", and not as "invalid" (like I said above).
Comment 5 Walter Bright 2011-04-12 11:15:01 UTC
void function() foo;

declares foo as a function pointer.

is(T T2 : T2*)

matches a pointer, and sets T2 to whatever is pointed to.

Hence what is printed out is correct. Not a bug.