Bug 2355 – is() doesn't resolve aliases before template matching

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-09-11T11:46:00Z
Last change time
2011-07-17T17:21:46Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
snake.scaly

Comments

Comment #0 by snake.scaly — 2008-09-11T11:46:28Z
template IsStatic(T : T[S], size_t S) {enum IsStatic = "true: " ~ T.stringof;} template IsStatic(T) {enum IsStatic = "false";} template IsStaticSmart(T) { static if (is(T E : E[S], size_t S)) enum IsStaticSmart = "true: " ~ E.stringof; else enum IsStaticSmart = "false"; } pragma(msg, IsStatic!(typeof("a"))); pragma(msg, IsStaticSmart!(typeof("a"))); Console output: >dmd -c test3.d true: invariant(char) false
Comment #1 by clugdbug — 2009-04-08T08:00:35Z
Actually, the bug is not really a problem with static arrays. The problem is just that is() isn't resolving aliases. If you replace 'size_t' with 'int' or 'uint', it works fine. BTW the original code no longer works, since literals are now dynamic arrays, not static arrays. -------- template IsStaticSmart(T) { static if (is( T E : E[S], int S)) enum IsStaticSmart = "true: " ~ E.stringof; else enum IsStaticSmart = "false"; } alias int AliasInt; template IsStaticSmart2(T) { static if (is( T E : E[S], AliasInt S)) enum IsStaticSmart2 = "true: " ~ E.stringof; else enum IsStaticSmart2 = "false"; } char [3] z; pragma(msg, IsStaticSmart!(typeof(z))); pragma(msg, IsStaticSmart2!(typeof(z))); DMD2.028 displays: true: char false
Comment #2 by yebblies — 2011-07-12T01:31:22Z
*** Issue 5830 has been marked as a duplicate of this issue. ***
Comment #3 by yebblies — 2011-07-12T01:41:18Z
Comment #4 by yebblies — 2011-07-12T18:25:35Z
*** Issue 6304 has been marked as a duplicate of this issue. ***
Comment #5 by bugzilla — 2011-07-17T17:21:46Z