www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24330] New: Redundant template instantiations for equal

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

          Issue ID: 24330
           Summary: Redundant template instantiations for equal
                    string/array literals
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

```
void g(string T)()
{
    pragma(msg, "g ", T, " ", T.stringof);
}

void h(ubyte[] T)()
{
    pragma(msg, "h ", T, " ", T.stringof);
}

void main()
{
    g!"a"();
    g!(['a'])();

    h!(cast(ubyte[])"a")();
    h!(['a'])();
}
```

Prints:

```
g a "a"
g a ['a']
h a "a"
h [cast(ubyte)97u] [cast(ubyte)97u]
```

Showing multiple instantiations are made. This is because internally, StringExp
and ArrayLiteralExp are hashed/mangled differently. An improvement would be to
consistently convert one to the other if possible.

--
Jan 11