[Issue 16581] New: Template shape misdetected in is() expression

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 3 09:39:14 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16581

          Issue ID: 16581
           Summary: Template shape misdetected in is() expression
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrei at erdani.com

Consider:

struct Test(T) {}

template PropagateQualifier(Q)
{
    static if (is(Q == immutable(Test!X), X))
        alias PropagateQualifier = immutable X;
    else static if (is(Q == const Test!X, X))
        alias PropagateQualifier = const X;
    else static if (is(Q == Test!X, X))
        alias PropagateQualifier = X;
    else static assert(0);
}

static assert(is(PropagateQualifier!(Test!char) == char));

This fails because PropagateQualifier!(Test!char) yields immutable(cha
r). Shuffling the three cases around reveals that the first is() test always
passes.

Inglorious workaround:

struct Test(T) {}

template PropagateQualifier(Q)
{
    static if (is(Q == immutable))
    {
        static if (is(Q == immutable(Test!X), X))
            alias PropagateQualifier = immutable X;
    }
    else static if (is(Q == const))
    {
        static if (is(Q == const(Test!X), X))
            alias PropagateQualifier = const X;
    }
    else static if (is(Q == Test!X, X))
        alias PropagateQualifier = X;
    else static assert(0);
}

static assert(is(PropagateQualifier!(Test!char) == char));
static assert(is(PropagateQualifier!(const(Test!char)) == const char));
static assert(is(PropagateQualifier!(Test!(immutable char)) == immutable
char));

--


More information about the Digitalmars-d-bugs mailing list