<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3942: Inconsistent use of const char_type&amp; in standard specializations of std::char_traits</title>
<meta property="og:title" content="Issue 3942: Inconsistent use of const char_type&amp; in standard specializations of std::char_traits">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3942.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#New">New</a> status.</em></p>
<h3 id="3942"><a href="lwg-active.html#3942">3942</a>. Inconsistent use of <code>const char_type&amp;</code> in standard specializations of <code>std::char_traits</code></h3>
<p><b>Section:</b> 27.2.4 <a href="https://wg21.link/char.traits.specializations">[char.traits.specializations]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2023-05-27 <b>Last modified:</b> 2023-06-01</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#char.traits.specializations">issues</a> in [char.traits.specializations].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In the standard specializations of <code>std::char_traits</code> (<code>std::char_traits&lt;char&gt;</code> etc.), there 
are a few member functions take a single character via a <code>const char_type&amp;</code> parameter, while other functions 
take a single character by value.
<p/>
In C++98, there were more functions taking <code>const char_type&amp;</code>. <a href="https://wg21.link/N2349" title=" Constant Expressions in the Standard Library —Revision 2">N2349</a> changed this in 
C++11 by making some, but not all of them take <code>char_type</code>. It is unclear whether the inconsistency is 
intended, and it seems better for these standard specializations to take a character by value.
<p/>
However, libstdc++ hasn't implemented the signature changes, perhaps due to ABI concerns. So it might be better 
to loose the restrictions for the purpose of standardization.
</p>

<p><i>[2023-06-01; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>



<p id="res-3942"><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> Two mutually exclusive options are prepared, depicted below by <b>Option A</b> and 
<b>Option B</b>, respectively.] 
</p>
</blockquote>

<p>
<b>Option A:</b> This assumes that "by-value" arguments are intended.
</p>

<ol>
<li>
<p>Modify the class template <code>char_traits</code> specialization synopses in 27.2.4.2 <a href="https://wg21.link/char.traits.specializations.char">[char.traits.specializations.char]</a>, 
27.2.4.3 <a href="https://wg21.link/char.traits.specializations.char8.t">[char.traits.specializations.char8.t]</a>, 27.2.4.4 <a href="https://wg21.link/char.traits.specializations.char16.t">[char.traits.specializations.char16.t]</a>, 
27.2.4.5 <a href="https://wg21.link/char.traits.specializations.char32.t">[char.traits.specializations.char32.t]</a>, and 27.2.4.6 <a href="https://wg21.link/char.traits.specializations.wchar.t">[char.traits.specializations.wchar.t]</a> 
as indicated:</p>

<blockquote>
<pre>
[&hellip;]
    static constexpr void assign(char_type&amp; c1, <del>const </del>char_type<del>&amp;</del> c2) noexcept;
[&hellip;]
    static constexpr const char_type* find(const char_type* s, size_t n,
                                           <del>const </del>char_type<del>&amp;</del> a);
[&hellip;]
</pre>
</blockquote>
</li>

</ol>

<p>
<b>Option B:</b> This assumes that implementation-freedom to keep ABI stability is intended.
</p>

<blockquote class="note">
<p>
[<i>Drafting Note:</i> It is intended to keep the <code>assign(s, n, a)</code> taking the character by value, 
because the argument may be a character in <code>[s, s + n)</code>.] 
</p>
</blockquote>

<ol>
<li>
<p>Add a paragraph at the end of 27.2.4.1 <a href="https://wg21.link/char.traits.specializations.general">[char.traits.specializations.general]</a> as indicated:</p>

<blockquote>
<p>
<ins>-?- For each occurrence of the placeholder <code><i>const-char-t</i></code> in the synopsis of each of these 
specializations, it is unspecified whether it denotes <code>char_type</code> or <code>const char_type&amp;</code>. 
Likewise, for each occurrence of the placeholder <code><i>const-int-t</i></code> in the synopsis of each of 
these specializations, it is unspecified whether it denotes <code>int_type</code> or <code>const int_type&amp;</code></ins>
</p>
</blockquote>
</li>

<li>
<p>Modify the class template <code>char_traits</code> specialization synopses in 27.2.4.2 <a href="https://wg21.link/char.traits.specializations.char">[char.traits.specializations.char]</a>, 
27.2.4.3 <a href="https://wg21.link/char.traits.specializations.char8.t">[char.traits.specializations.char8.t]</a>, 27.2.4.4 <a href="https://wg21.link/char.traits.specializations.char16.t">[char.traits.specializations.char16.t]</a>, 
27.2.4.5 <a href="https://wg21.link/char.traits.specializations.char32.t">[char.traits.specializations.char32.t]</a>, and 27.2.4.6 <a href="https://wg21.link/char.traits.specializations.wchar.t">[char.traits.specializations.wchar.t]</a> 
as indicated:</p>

<blockquote>
<pre>
[&hellip;]
    static constexpr void assign(char_type&amp; c1, <del>const char_type&amp;</del><ins><i>const-char-t</i></ins> c2) noexcept;
    static constexpr bool eq(<del>char_type</del><ins><i>const-char-t</i></ins> c1, <del>char_type</del><ins><i>const-char-t</i></ins> c2) noexcept;
    static constexpr bool lt(<del>char_type</del><ins><i>const-char-t</i></ins> c1, <del>char_type</del><ins><i>const-char-t</i></ins> c2) noexcept;
[&hellip;]
    static constexpr const char_type* find(const char_type* s, size_t n,
                                           <del>const char_type&amp;</del><ins><i>const-char-t</i></ins> a);
[&hellip;]
    static constexpr int_type not_eof(<del>int_type</del><ins><i>const-int-t</i></ins> c) noexcept;
    static constexpr char_type to_char_type(<del>int_type</del><ins><i>const-int-t</i></ins> c) noexcept;
    static constexpr int_type to_int_type(<del>char_type</del><ins><i>const-char-t</i></ins> c) noexcept;
    static constexpr bool eq_int_type(<del>int_type</del><ins><i>const-int-t</i></ins> c1, <del>int_type</del><ins><i>const-int-t</i></ins> c2) noexcept;
[&hellip;]
</pre>
</blockquote>
</li>

</ol>





</body>
</html>
