Bug 6879 – The difference of between template matching and IsExp

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-02T04:57:00Z
Last change time
2011-11-14T22:45:22Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2011-11-02T04:57:00Z
I think following code should compile. ---- private template isStaticArray(T : U[N], U, size_t N) { enum bool isStaticArray = true; } private template isStaticArray(T) { enum bool isStaticArray = false; } void main() { alias int[3] T; enum res1 = isStaticArray!T; static if (is(T _ : U[N], U, size_t N)) enum res2 = true; else enum res2 = false; static assert(res1 == res2); // fails... Why? }
Comment #1 by k.hara.pg — 2011-11-02T06:00:41Z
When static if condition is same as follows, the judgement succeeds. static if (is(T _ : X, X : U[N], U, size_t N)) ... This works as expected, but unneeded two symbols require (_ and X). It seems to me that this syntax has little confusing.
Comment #2 by k.hara.pg — 2011-11-02T07:44:11Z
I have found the true issue. alias int[3] T; static if (is(T _ : U[N], U, int N)) // a: match static if (is(T _ : U[N], U, uint N)) // b: match static if (is(T _ : U[N], U, size_t N)) // c: doesn't match The mismatching of c is 'rejects-valid' issue IMO.
Comment #3 by k.hara.pg — 2011-11-02T09:13:04Z
Comment #4 by bugzilla — 2011-11-14T22:45:22Z