Bug 20614 – CTFE supports typeid(stuff).name but not classinfo.name
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-26T14:29:13Z
Last change time
2020-04-16T18:47:55Z
Keywords
CTFE
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2020-02-26T14:29:13Z
This commit https://github.com/dlang/dmd/pull/10796, adds support for retireving the dynamic class name at compile time. but it only works with typeid and not classinfo, which should be supported too since therey are the same thing.
---
string classname(Object o)
{
return typeid(o).name;
}
string classnameAlt(Object o)
{
return o.classinfo.name;
}
class Panzer {}
class Tiger : Panzer {}
static assert (() {
Panzer p = new Tiger(); return classname(p);
} () == "Tiger"); // OK
static assert (() {
Panzer p = new Tiger(); return classnameAlt(p);
} () == "Tiger"); // NG
---