← Back to index
|
Original Bugzilla link
Bug 16581 – Template shape misdetected in is() expression
Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-10-03T16:39:14Z
Last change time
2024-12-13T18:50:21Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Moved to GitHub: dmd#17777 →
Comments
Comment #0
by andrei — 2016-10-03T16:39:14Z
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));
Comment #1
by robert.schadek — 2024-12-13T18:50:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/dmd/issues/17777
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB