[Issue 14820] New: Templates not reevaluated inside static loop unrolling

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 22 07:16:44 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14820

          Issue ID: 14820
           Summary: Templates not reevaluated inside static loop unrolling
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: simendsjo at gmail.com

The summary text might be wrong as I'm not sure what the root cause is. The
template is just evaluated on the first loop even though the underlying value
changes:

The following code:

template TypeOf(alias T) {
    pragma(msg, "TypeOf evaluated with ", T.stringof);
    alias TypeOf = typeof(T);
}

void main() {
    import std.typetuple;

    foreach(type; TypeTuple!(int, short))
    {
        type a;
        pragma(msg, "loop:")
        pragma(msg, "  type: ", type);
        pragma(msg, "  a: ", typeof(a));
        alias t = TypeOf!a;
        pragma(msg, "  TypeOf: ", t);
    }
}

Produces the following output:

loop:
  type: int
  a: int
TypeOf evaluated with a
  TypeOf: int
loop:
  type: short
  a: short
  TypeOf: int

Notice that the TypeOf template is only evaluated for the first pass through
the loop.

--


More information about the Digitalmars-d-bugs mailing list