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

James Skene via libcxx-dev libcxx-dev at lists.llvm.org
Tue Aug 4 20:45:21 PDT 2020

On Wed, 5 Aug 2020 at 13:35, Marshall Clow <mclow.lists at gmail.com> wrote:

> On Aug 4, 2020, at 4:33 PM, James Skene <j.skene at gmail.com> wrote:
> On Wed, 5 Aug 2020 at 10:18, Marshall Clow <mclow.lists at gmail.com> wrote:
>> On Aug 4, 2020, at 2:41 PM, James Skene <j.skene at gmail.com> wrote:
>> The general templates would be declared as per the spec.  The member
>> functions would be defined something like this:
>> Sure, they *could* be defined something like that.
>> But my point is that a conforming implementation need not have
>> `numpunct<char16_t>` at all.
>> — Marshall
> And that comes down to the interpretation of the specification.  Your
> position, as I understand it, is that the specification does not require
> the general template to be defined.
> My position is that if you attempt to instantiate `numpunct<char16_t>`,
> that is not required to succeed.
> But I don't see the justification for that in the letter of the
> specification.  And neither is this the position that GCC or Visual Studio
> take.  So what am I failing to understand?
> What makes you think that the Visual Studio maintainers (or the libtdc++
> maintainers) believe that those are required?
> I see that:
> 1) The standard requires that some specializations exist.
> 2) libstdc++ and Visual Studio provide those, and more.
> They’re allowed to do that.
> That’s different from believing that they are required.
> — Marshall
Well, I have already more or less explicitly given three reasons why I
think they are required, and they are good enough reasons that I expect the
maintainers of VS and libstdc++ probably agree with me:

1. It looks to me that the standard says they are required ( and
nowhere does it say they are not required;

2. Other implementers provide them;

3. Implementing them actually *doesn't* require any major effort of
implementation or the introduction of platform or locale dependent code
into the library, so we can't assume that the standard means for them to be
excluded on that basis.

To this list I will add:

4. The classes of the locale and Input/Output library are everywhere class
templates parameterised by character type, and the possibility of extending
support for other character types is explicitly extended to library
implementers at least; nor is it explicitly denied to user code, and
furthermore the standard library anticipates user extensions, and gives
rules for how the standard library can be extended in user code.  But if
those two class templates, ctype and numpunct are omitted, then the
formatted output operators for std::basic_ostream cannot be reused for
char16_t and char32_t (or any other primitive type) by user code, because
user code cannot define and add those facets for the different character
type to their locale.  User code is explicitly prevented from defining just
those facets by the injunction ( 'A program may add a template
specialization for any standard library template to namespace std only if
the declaration depends on a user-defined type and the specialization meets
the  library requirements for the original template and is not explicitly
prohibited.'  The specialisations std::ctype<char16_t>,
std::numpunct<char16_t>, std::ctype<char32_t>, std::numpunct<char32_t> do
not depend on any user-defined type and so cannot be defined in user code.

So did the designers of the C++ language and standard library, a group
which you may count yourself a member of, Marshall, really provide their
users with a library that seems extensible, and character types that seem
perfect to use to extend it, but with the intent that this should not in
fact be done and that nobody should be silly enough to try?  And to make
sure that nobody tries, they make the effort impossible due to a
technicality involving two obscure aspects of the localisation library, and
don't even even bother to include a note to that effect in the

Also, leaving aside the question of whether excluding these templates is an
error, you should want to include them anyway because doing so
significantly improves the utility of your implementation.  Under GNU and
VS the following works:

std::basic_stringstream<char16_t> s;
s << u"Hello world";

The same code fails to compile with libc++ because 'Implicit instantiation
of undefined template 'std::__1::ctype<char16_t>'.  Note that neither the
VS or GNU implementations depend on any explicitly specialised templates or
char16_t-specific code to make the above work, so they are not actually
providing anything beyond the specification - at least if you believe, as I
do, that the base template of ctype should be included in the

So putting to one side the state of *my* knowledge, what do *you* know that
convinces you that all these reasons are wrong and these templates are not

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20200805/a0e64c54/attachment.html>

More information about the libcxx-dev mailing list