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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Peter Dimov from comment #7)
> You don't necessarily need dynamic_cast because facets are always installed
> and obtained by their exact type, not via a reference to base.

Is that true? std::use_facet<X> will return a reference to a facet with X::id
but it could actually be something derived from X. e.g. a user can install
their own facet derived from std::ctype<char>, which overrides some members.
Code that does std::use_facet<std::ctype<char>>(loc) will get the user's facet,
but via reference to base.

> You can store
> the Facet* as given (like shared_ptr does), and return it.
> 
> The only reason dynamic_cast is needed here is because you can't static_cast
> from facet* to Facet* when virtual inheritance. But you are not required to
> store facet* in the actual container; you can store the original Facet* as
> void*.

An implementation could do that, but I don't think libstdc++ can do it now
without an ABI change.

Reply via email to