On Thursday, 13 August 2015 at 16:05:19 UTC, Steven Schveighoffer
wrote:
On 8/13/15 11:59 AM, Steven Schveighoffer wrote:
That is definitely a bug. It's because typeid is looking up
the derived
type via the vtable, but the compiler should rewrap it with
'shared'
afterwards.
Actually, now that I think about it, I'm not sure how the
compiler can figure this out.
There would have to be a way to construct a TypeInfo_Shared at
runtime, which the compiler shouldn't be doing. Alternatively,
it could proactively create a TypeInfo_Shared (and all the
other flavors) for each class type in the runtime, and then
look it up using some hash mechanism.
This likely isn't fixable.
What you CAN do, however, is:
typeid(typeof(c))
Which should get the *static* type (and that should be
TypeInfo_Shared in both struct and class instances).
So likely this is not a bug, or at the best, a wontfix.
If it yields invalid results, it should at least be forbidden, if
it can't be fixed.