www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2355] New: is() fails to recognize a static array

reply d-bugmail puremagic.com writes:

           Summary: is() fails to recognize a static array
           Product: D
           Version: 2.019
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: snake.scaly gmail.com

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;
    enum IsStaticSmart = "false";

pragma(msg, IsStatic!(typeof("a")));
pragma(msg, IsStaticSmart!(typeof("a")));

Console output:

dmd -c test3.d

false --
Sep 11 2008
parent d-bugmail puremagic.com writes:

clugdbug yahoo.com.au changed:

           What    |Removed                     |Added
            Summary|is() fails to recognize a   |is() doesn't resolve aliases
                   |static array                |before template matching

------- Comment #1 from clugdbug yahoo.com.au  2009-04-08 08:00 -------
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;
    enum IsStaticSmart = "false";

alias int AliasInt;

template IsStaticSmart2(T) {
  static if (is( T E : E[S], AliasInt S))
    enum IsStaticSmart2 = "true: " ~ E.stringof;
    enum IsStaticSmart2 = "false";

char [3] z;

pragma(msg, IsStaticSmart!(typeof(z)));
pragma(msg, IsStaticSmart2!(typeof(z)));

DMD2.028 displays:
true: char

Apr 08 2009