Bug 2369 – is(T == function) does not recognize function pointers

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-09-21T19:49:00Z
Last change time
2015-06-09T01:20:16Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
snake.scaly

Comments

Comment #0 by snake.scaly — 2008-09-21T19:49:44Z
Consider the example: template IsFun(T) { static if (is(T == function)) { enum IsFun = T.stringof ~ ": fun"; } else { enum IsFun = T.stringof ~ ": not fun"; } } void foo() {} pragma(msg, IsFun!(typeof(foo))); // (void())(): fun pragma(msg, IsFun!(typeof(&foo))); // void function(): not fun I expect both forms to be detected as functions.
Comment #1 by bugzilla — 2008-10-04T16:43:13Z
But they aren't both functions. One is a function, the other is a pointer to a function. If both were recognized as functions, then one could not distinguish between the two.
Comment #2 by snake.scaly — 2008-10-04T17:11:19Z
The type is called function, you create a value of that type using the function keyword, so I expected the is(T==function) to detect this type. I think the whole is(==) system works strangely. Let's take four cases: void foo() {} class Bar { void bar() {} } Bar b; typeof(foo) // (void())() typeof(&foo) // void function() typeof(b.bar) // (void())() typeof(&b.bar) // void delegate() is(T==function) only true for typeof(foo) is(T==delegate) only true for typeof(&b.bar) is(T:T*) is false for any of them. I'd really like more predictable behavior.