[libcxx-dev] std::ctype, std::numpunct base templates

Marshall Clow via libcxx-dev libcxx-dev at lists.llvm.org
Mon Aug 3 22:30:52 PDT 2020

On Aug 3, 2020, at 8:25 PM, James Skene via libcxx-dev <libcxx-dev at lists.llvm.org> wrote:
> Hi,
> I'm considering submitting a bug report against libc++, but thought I would check here first.
> The standard gives a synopsis for the locale facet std::ctype<CharT> in Section 25.4.1 (C++17, but it is also in C++11), and std::numpunct<CharT> in Section 25.4.3.  Under libc++ specialisations of these templates are defined for char and wchar_t (in header '__locale') but the base template definition is omitted.  This means in particular that I cannot define:
> class my_ctype : public std::ctype<char16_t> { ... };
> class my_numpunct : public std::numpunct<char16_t> { ... };

Yes, I believe that this is correct.

> This seems to go against the intent of these classes, which include abstract virtual function declarations.  Although clause 30.2.2 restricts the support for stream-based I/O that an implementation must provide to the types char and wchar_t, it is not clear to me that this means the definitions of the above templates can be omitted.
> I would appreciate advice as to: a. whether this is actually an issue or my misreading of the spec; and b. if so, if it is a known issue.

https://wg21.link/locale.category lists the required specializations for numpunct and ctype.

It doesn’t say anything about the general template.

So, I would say this is not a bug.

From an implementation point of view, the implementations of ctype<char> and type<wchar_t> are fairly different, and have a lot of system -specific knowledge baked into them. I don’t think I really know enough about charXX_t (8/16/32) on various systems to provide high-quality implementations (and in the case of char32_t, in a reasonable size of code/data). ICU does much of this, but it’s quite large.

— Marshall

More information about the libcxx-dev mailing list