Почему std :: isgraph вызывает исключение в std :: use_facet? - PullRequest
0 голосов
/ 19 января 2019
bool foo (char32_t code_point)
{
    static std::locale loc ("en_US.utf8");
    return std::isgraph (code_point, loc);
}

foo ('B');

Это исключение:

  /**
   *  @brief  Return a facet.
   *  @ingroup locales
   *
   *  use_facet looks for and returns a reference to a facet of type Facet
   *  where Facet is the template parameter.  If has_facet(locale) is true,
   *  there is a suitable facet to return.  It throws std::bad_cast if the
   *  locale doesn't contain a facet of type Facet.
   *
   *  @tparam  _Facet  The facet type to access.
   *  @param  __loc  The locale to use.
   *  @return  Reference to facet of type Facet.
   *  @throw  std::bad_cast if @p __loc doesn't contain a facet of type _Facet.
  */
  template<typename _Facet>
    const _Facet&
    use_facet(const locale& __loc)
    {
      const size_t __i = _Facet::id._M_id();
      const locale::facet** __facets = __loc._M_impl->_M_facets;
      if (__i >= __loc._M_impl->_M_facets_size || !__facets[__i])
        __throw_bad_cast();
#if __cpp_rtti
      return dynamic_cast<const _Facet&>(*__facets[__i]);
#else
      return static_cast<const _Facet&>(*__facets[__i]);
#endif
    }

Он вызывает __throw_bad_cast(), потому что __i==46, что равно _M_facets_size.

Примечание: документация гласит: It throws std::bad_cast if the locale doesn't contain a facet of type Facet.

Но я не знаю, что это значит.

В моем Ubuntu locale -a включает en_US.utf8, а структура loc выглядит разумно в отладчике:

enter image description here

Почему isgraph выдает исключение?

...