[Issue 2873] New: typeof() for member functions evaluated incorrectly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 21 18:12:41 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2873

           Summary: typeof() for member functions evaluated incorrectly
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: dsimcha at yahoo.com


// Copied/pasted from std.range, added pragma.
template hasLength(R)
{
    pragma(msg, typeof(R.init.length).stringof);  // (uint())()
    enum bool hasLength = is(typeof(R.init.length) : ulong);
}

struct Foo {
    uint length() {
        return 0;
    }
}

const Foo foo;

static assert(hasLength!(Foo));  // Fails.

This is pretty serious because it makes important functionality in the new
Phobos unusable.  However, an easy workaround to fix Phobos until the
underlying DMD bug gets fixed is:

enum bool hasLength = is(typeof(R.init.length) : ulong) ||
                      is(typeof(R.init.length()) : ulong);

Also, what the heck is a (uint())() ?


-- 



More information about the Digitalmars-d-bugs mailing list