[Issue 24330] New: Redundant template instantiations for equal string/array literals
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 11 14:49:42 UTC 2024
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 at puremagic.com
Reporter: dkorpel at 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.
--
More information about the Digitalmars-d-bugs
mailing list