D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20614 - CTFE supports typeid(stuff).name but not classinfo.name
Summary: CTFE supports typeid(stuff).name but not classinfo.name
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: CTFE
Depends on:
Blocks:
 
Reported: 2020-02-26 14:29 UTC by basile-z
Modified: 2020-04-16 18:47 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description basile-z 2020-02-26 14:29:13 UTC
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
---
Comment 1 basile-z 2020-04-16 18:47:55 UTC
because of https://issues.dlang.org/show_bug.cgi?id=8059