<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2392: "character type" is used but not defined</title>
<meta property="og:title" content="Issue 2392: &quot;character type&quot; is used but not defined">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2392.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#WP">WP</a> status.</em></p>
<h3 id="2392"><a href="lwg-defects.html#2392">2392</a>. "character type" is used but not defined</h3>
<p><b>Section:</b> 3.36 <a href="https://wg21.link/defns.ntcts">[defns.ntcts]</a>, 28.3.3.1.2.1 <a href="https://wg21.link/locale.category">[locale.category]</a>, 31.2.3 <a href="https://wg21.link/iostreams.limits.pos">[iostreams.limits.pos]</a>, 31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>, 31.7.6.3.4 <a href="https://wg21.link/ostream.inserters.character">[ostream.inserters.character]</a> <b>Status:</b> <a href="lwg-active.html#WP">WP</a>
 <b>Submitter:</b> Jeffrey Yasskin <b>Opened:</b> 2014-06-01 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The term "character type" is used in 3.36 <a href="https://wg21.link/defns.ntcts">[defns.ntcts]</a>, 28.3.3.1.2.1 <a href="https://wg21.link/locale.category">[locale.category]</a>,
31.2.3 <a href="https://wg21.link/iostreams.limits.pos">[iostreams.limits.pos]</a>, 31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>, and
31.7.6.3.4 <a href="https://wg21.link/ostream.inserters.character">[ostream.inserters.character]</a>, but the core language only defines
"narrow character types" (6.9.2 <a href="https://wg21.link/basic.fundamental">[basic.fundamental]</a>).
<p/>
"wide-character type" is used in 99 [depr.locale.stdcvt], but the core
language only defines a "wide-character set" and "wide-character literal".
</p>

<p><i>[2023-06-14; Varna; Daniel comments and provides wording]</i></p>

<p>
Given the resolution of <a href="https://wg21.link/P2314" title=" Character sets and encodings">P2314</a> which had introduced to
6.9.2 <a href="https://wg21.link/basic.fundamental">[basic.fundamental]</a> p11 a definition of "character type":
</p>
<blockquote><p>
The types <code>char</code>, <code>wchar_t</code>, <code>char8_t</code>, <code>char16_t</code>, <code>char32_t</code> are collectively
called <i>character types</i>.
</p></blockquote>
<p>
one might feel tempted to have most parts of this issue resolved here, but I think that this
actually is a red herring.
<p/>
First, as Jonathan already pointed out, for two places, 31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a> and
31.7.6.3.4 <a href="https://wg21.link/ostream.inserters.character">[ostream.inserters.character]</a>, this clearly doesn't work, instead it seems as if we 
should replace "character type of the stream" here by "<code>char_type</code> of the stream".
<p/>
To me "<code>char_type</code> of the stream" sounds a bit odd (we usually refer to <code>char_type</code>
in terms of a qualified name such as <code>X::char_type</code> instead unless we are specifying
a member of some <code>X</code>, where we can omit the qualification) and in the suggested
wording below I'm taking advantage of the already defined term "character container type"
(3.10 <a href="https://wg21.link/defns.character.container">[defns.character.container]</a>) instead, which seems to fit its intended purpose here.
<p/>
Second, on further inspection it turns out that actually only <em>one</em> usage of the
term "character type" seems to be intended to refer to the actual core language meaning (See
the unchanged wording for 28.3.4.3.3.3 <a href="https://wg21.link/facet.num.put.virtuals">[facet.num.put.virtuals]</a> in the proposed wording
below), all other places quite clearly must refer to the above mentioned
"character container type".
<p/>
For the problem related to the missing definition of "wide-character type" (used two times in
99 [depr.locale.stdcvt]) I would like to suggest a less general and less inventive
approach to solve the definition problem here, because it only occurs in an already deprecated
component specification: My suggestion is to simply get rid of that term
by just identifying <code>Elem</code> with being one of <code>wchar_t</code>, <code>char16_t</code>, or, 
<code>char32_t</code>. (This result is identical to identifying "wide-character type" with
a "character type that is not a narrow character type (6.9.2 <a href="https://wg21.link/basic.fundamental">[basic.fundamental]</a>)", but this
seemingly more general definition doesn't provide a real advantage.)
</p>

<p><i>[Varna 2023-06-14; Move to Ready]</i></p>


<p><i>[2023-06-25; Daniel comments]</i></p>

<p>
During the Varna LWG discussions of this issue it had been pointed out that the wording change applied to
 [depr.locale.stdcvt.req] bullet (1.1) could exclude now the previously allowed support
of narrow character types as a "wide-character" with e.g. a <code>Maxcode</code> value of 255. First,
I don't think that the revised wording really forbids this. Second, the originating proposal
<a href="https://wg21.link/N2401" title=" Code Conversion Facets for the Standard C++ Library">N2401</a> doesn't indicate what the actual intend here was and it seems questionable to
assign LEWG to this issue given that the relevant wording is part of deprecated components, especially
given their current position expressed <a href="https://github.com/cplusplus/papers/issues/1527#issuecomment-1565907454">here</a>
to eliminate the specification of the affected components as suggested by <a href="https://wg21.link/P2871" title=" Remove Deprecated Unicode Conversion Facets From C++26">P2871</a>.
</p>
<p><i>[2023-11-11 Approved at November 2023 meeting in Kona. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-2392"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4950" title=" Working Draft, Standard for Programming Language C++">N4950</a>.
</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> All usages of "character type" in 28.5 <a href="https://wg21.link/format">[format]</a> seem to be without problems.]
</p>
</blockquote>

<ol>
<li><p>Modify 28.3.3.1.2.1 <a href="https://wg21.link/locale.category">[locale.category]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> The more general interpretation of "character container type" instead of character type by
the meaning of the core language seems safe here. It seems reasonable that an implementation allows more than
the core language character types, but still could impose additional constraints imposed on them. Even if an implementation
does never intend to support anything beyond <code>char</code> and <code>wchar_t</code>, the wording below is harmless.
One alternative could be here to use the even more general term "char-like types" from 27.1 <a href="https://wg21.link/strings.general">[strings.general]</a>, 
but I'm unconvinced that this buys us much]
</p>
</blockquote>

<blockquote>
<p>
-6- [&hellip;] A template parameter with name <code>C</code> represents the
set of types containing <code>char</code>, <code>wchar_t</code>, and any other implementation-defined 
character <ins>container</ins> types <ins>(3.10 <a href="https://wg21.link/defns.character.container">[defns.character.container]</a>)</ins> that meet the
requirements for a character on which any of the iostream components can be instantiated. [&hellip;]
</p>
</blockquote>

</li>

<li><p>Keep 28.3.4.3.3.3 <a href="https://wg21.link/facet.num.put.virtuals">[facet.num.put.virtuals]</a> of <b>Stage 1</b> following p4 <em>unchanged</em>:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> The wording here seems to refer to the pure core language wording meaning of a character type.]
</p>
</blockquote>

<blockquote>
<p>
[&hellip;] For conversion from an integral type other than a character type, the function determines the
integral conversion specifier as indicated in Table 110.
</p>
</blockquote>

</li>

<li><p>Modify 31.2.3 <a href="https://wg21.link/iostreams.limits.pos">[iostreams.limits.pos]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> Similar to 28.3.3.1.2.1 <a href="https://wg21.link/locale.category">[locale.category]</a> above the more general interpretation of "character container type" 
instead of character type by the meaning of the core language seems safe here. ]
</p>
</blockquote>

<blockquote>
<p>
-3- In the classes of Clause 31, a template parameter with name <code>charT</code> represents a member of the set of types
containing <code>char</code>, <code>wchar_t</code>, and any other implementation-defined character <ins>container</ins> types 
<ins>(3.10 <a href="https://wg21.link/defns.character.container">[defns.character.container]</a>)</ins> that meet the requirements
for a character on which any of the iostream components can be instantiated.
</p>
</blockquote>

</li>

<li><p>Modify 31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a> as indicated:</p>

<blockquote>
<p>
-3- If a formatted output function of a stream <code>os</code> determines padding, it does so as follows. Given a <code>charT</code>
character sequence <code>seq</code> where <code>charT</code> is the character <ins>container</ins> type of the stream, [&hellip;]
</p>
</blockquote>

</li>

<li><p>Modify 31.7.6.3.4 <a href="https://wg21.link/ostream.inserters.character">[ostream.inserters.character]</a> as indicated:</p>

<blockquote><pre>
template&lt;class charT, class traits&gt;
  basic_ostream&lt;charT, traits&gt;&amp; operator&lt;&lt;(basic_ostream&lt;charT, traits&gt;&amp; out, charT c);
template&lt;class charT, class traits&gt;
  basic_ostream&lt;charT, traits&gt;&amp; operator&lt;&lt;(basic_ostream&lt;charT, traits&gt;&amp; out, char c);
// specialization
template&lt;class traits&gt;
  basic_ostream&lt;char, traits&gt;&amp; operator&lt;&lt;(basic_ostream&lt;char, traits&gt;&amp; out, char c);
// signed and unsigned
template&lt;class traits&gt;
  basic_ostream&lt;char, traits&gt;&amp; operator&lt;&lt;(basic_ostream&lt;char, traits&gt;&amp; out, signed char c);
template&lt;class traits&gt;
  basic_ostream&lt;char, traits&gt;&amp; operator&lt;&lt;(basic_ostream&lt;char, traits&gt;&amp; out, unsigned char c);
</pre>
<blockquote>
<p>
-1- <i>Effects</i>: Behaves as a formatted output function (31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>) of <code>out</code>. 
Constructs a character sequence <code>seq</code>. If <code>c</code> has type <code>char</code> and the character <ins>container</ins> 
type of the stream is not <code>char</code>, then <code>seq</code> consists of <code>out.widen(c)</code>; otherwise <code>seq</code> 
consists of <code>c</code>. Determines padding for <code>seq</code> as described in 31.7.6.3.1 <a href="https://wg21.link/ostream.formatted.reqmts">[ostream.formatted.reqmts]</a>. 
Inserts <code>seq</code> into <code>out</code>. Calls <code>os.width(0)</code>.
</p>
</blockquote>
</blockquote>

</li>

<li><p>Modify  [depr.locale.stdcvt.req] as indicated:</p>

<blockquote>
<ol style="list-style-type: none">
<li><p>(1.1) &mdash; <code>Elem</code> is <ins>one of</ins><del>the wide-character type, such as</del> 
<code>wchar_t</code>, <code>char16_t</code>, or <code>char32_t</code>.</p></li>
<li><p>(1.2) &mdash; <code>Maxcode</code> is the largest <del>wide-character code</del> 
<ins>value of <code>Elem</code> converted to <code>unsigned long</code></ins> that the facet will read or 
write without reporting a conversion error.</p></li>
<li><p>[&hellip;]</p></li>
</ol>
</blockquote>

</li>
</ol>





</body>
</html>
