www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2369] New: is(T == function) does not recognize function pointers

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

           Summary: is(T == function) does not recognize function pointers
           Product: D
           Version: 2.019
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: snake.scaly gmail.com


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.


-- 
Sep 21 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2369


bugzilla digitalmars.com changed:

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





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.


-- 
Oct 04 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2369






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.


-- 
Oct 04 2008