digitalmars.D.bugs - [Issue 16581] New: Template shape misdetected in is() expression
- via Digitalmars-d-bugs (52/52) Oct 03 2016 https://issues.dlang.org/show_bug.cgi?id=16581
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 puremagic.com Reporter: andrei 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)); --
Oct 03 2016