[Bug c++/96356] RTTI for non-polymorphic typeid

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jul 28 14:50:42 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96356

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It would be theoretically possible for the compiler to elide some RTTI code
when the effects are known at compile time, e.g. so typeid(int)==typeid(int) is
always true, and typeid(int)==typeid(long) is always false, even without RTTI.

But that isn't going to help your case, where std::any::type<T>() still has to
return something, and unless the creation of the std::any and the call to
type<T>() are both visible to the compiler and inlined, then you're not going
to get something equivalent to typeid(A)==typeid(B) where the types are known
at compile time.

Such an optimisation seems likely to only work in "embarrassingly simple" cases
where you don't actually need to use typeid anyway. If it doesn't work in
actually useful cases (where the types aren't known in advance because the
types depend on run time conditions) then implementing that optimisation seems
like a waste of time.  No sensible code is going to use typeid when all the
types are known at compile time, because you wouldn't bother using type erasure
or RTTI in such cases.

Not a bug.


More information about the Gcc-bugs mailing list