how to get typeid of extern(C++) classes?
Steven Schveighoffer
schveiguy at yahoo.com
Fri Feb 16 21:44:37 UTC 2018
On 2/15/18 7:42 PM, Timothee Cour wrote:
> is there a way to get typeid of extern(C++) classes (eg for ones in
> dmd/astbase.d but not limited to that) ?
> C++ exposes it via typeid so in theory all the info is there ;
> I would need it at least for debugging (eg if RTTI is not enabled for
> all compilers or in release mode that's fine so long there's a
> documented way to get it for debugging)
>
> a lot of extern(C++) classes in dmd use hacks like enum values to get
> their type but it's unreliable and doesn't work for all AST classes.
>
> at least having a way to expose typeid(instance).name() would be a start
>
> also, that could be used to fix the bug I posted here:
> https://forum.dlang.org/post/mailman.3138.1517949584.9493.digitalmars-d@puremagic.com
> cast overly permissive with extern(C++ ) classes; ( ie that `cast(A)
> b` doesn't care that b is of dynamic type A)
>
typeid always returns a D TypeInfo object, which is a D-specific animal.
I don't think we can do this for C++ classes.
For D classes in particular, the typeid is a runtime type, gleaned from
the embedded vtable. For structs, it is a compile-time defined
reference. Neither of these things would exist for C++ classes.
-Steve
More information about the Digitalmars-d
mailing list