<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3314: Is stream insertion behavior locale dependent when Period::type is micro?</title>
<meta property="og:title" content="Issue 3314: Is stream insertion behavior locale dependent when Period::type is micro?">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3314.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#C++20">C++20</a> status.</em></p>
<h3 id="3314"><a href="lwg-defects.html#3314">3314</a>. Is stream insertion behavior locale dependent when <code>Period::type</code> is <code>micro</code>?</h3>
<p><b>Section:</b> 30.5.11 <a href="https://wg21.link/time.duration.io">[time.duration.io]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Tom Honermann <b>Opened:</b> 2019-11-04 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#time.duration.io">issues</a> in [time.duration.io].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
30.5.11 <a href="https://wg21.link/time.duration.io">[time.duration.io]</a> states:
</p>
<blockquote>
<pre>
template&lt;class charT, class traits, class Rep, class Period>
  basic_ostream&lt;charT, traits&gt;&amp;
    operator&lt;&lt;(basic_ostream&lt;charT, traits&gt;&amp; os, const duration&lt;Rep, Period&gt;&amp; d);
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-3- The units suffix depends on the type <code>Period::type</code> as follows:
<ol style="list-style-type: none">
<li><p>[&hellip;]</p></li>
<li><p>(3.5) &mdash; Otherwise, if <code>Period::type</code> is <code>micro</code>, the suffix is <code>"&micro;s"</code> 
(<code>"\u00b5\u0073"</code>).</p></li>
<li><p>[&hellip;]</p></li>
</ol>
<p/>
[&hellip;]
<p/>
-4- If <code>Period::type</code> is <code>micro</code>, but the character U+00B5 cannot be represented in the 
encoding used for <code>charT</code>, the unit suffix <code>"us"</code> is used instead of <code>"&micro;s"</code>.
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
<p>
Which encoding is intended by "the encoding used for <code>charT</code>"?  There are two candidates:
</p>
<ol>
<li><p>The associated execution character set as defined by 5.3.1 <a href="https://wg21.link/lex.charset">[lex.charset]</a> p3 used to encode 
character and string literals (e.g., the "execution wide-character set" for <code>wchar_t</code>).</p></li>
<li><p>The locale dependent character set used by the <code>std::locale ctype</code> and <code>codecvt</code> 
facets as specified in 28.3.4.2 <a href="https://wg21.link/category.ctype">[category.ctype]</a>, sometimes referred to as the 
"native character set".</p></li>
</ol>
<p>
The behavior should not be dependent on <code>locale</code> and should therefore be specified in terms of 
the execution character sets.
<p/>
The execution character set is implementation defined and some implementations allow the choice of 
execution character set to be specified via a compiler option or determined based on the locale active 
when the compiler is run. For example, the Microsoft compiler, when run on a Windows system with regional 
language settings configured for "English (United States)", will use Windows-1252 for the execution 
character set, but allows this choice to be overridden with the <code>/execution-charset</code> compiler 
option. The Microsoft compiler might therefore use <code>"us"</code> by default, but <code>"&micro;s"</code> 
when invoked with the <code>/execution-charset:utf-8</code> or <code>/execution-charset:.437</code> options. 
In the latter two cases, the string contents would contain <code>"\xb5\x73"</code> and <code>"\xe6\x73"</code> 
respectively (Unicode and Windows code page 437 map &micro; (U+00B5, MICRO SIGN) to different code points).
<p/>
This resolution relies on the character set for the locale used at run-time being compatible with the 
execution character set if the produced string is to be displayed correctly when written to a terminal 
or console. This is a typical requirement for character and string literals but is more strongly 
relevant for this issue since &micro; lacks representation in many character sets. Additionally, if the 
stream is imbued with a <code>std::codecvt</code> facet, the facet must provide appropriate conversion 
support for behavior to be well defined.
</p>

<p><i>[2019-11 Priority to 2 during Tuesday morning issue processing in Belfast.]</i></p>


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4835">N4835</a>.</p>

<ol>
<li><p>Modify 30.5.11 <a href="https://wg21.link/time.duration.io">[time.duration.io]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> "implementation's native character set" is used in 28.3.4.2.2 <a href="https://wg21.link/locale.ctype">[locale.ctype]</a> 
and 28.3.4.2.5 <a href="https://wg21.link/locale.codecvt">[locale.codecvt]</a> to refer to the locale dependent character encoding.]
</p>
</blockquote>

<blockquote>
<pre>
template&lt;class charT, class traits, class Rep, class Period>
  basic_ostream&lt;charT, traits&gt;&amp;
    operator&lt;&lt;(basic_ostream&lt;charT, traits&gt;&amp; os, const duration&lt;Rep, Period&gt;&amp; d);
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-3- The units suffix depends on the type <code>Period::type</code> as follows:
<ol style="list-style-type: none">
<li><p>[&hellip;]</p></li>
<li><p>(3.5) &mdash; Otherwise, if <code>Period::type</code> is <code>micro</code>, the suffix is <code>"&micro;s"</code> 
(<code>"\u00b5\u0073"</code>).</p></li>
<li><p>[&hellip;]</p></li>
</ol>
<p/>
[&hellip;]
<p/>
-4- If <code>Period::type</code> is <code>micro</code>, but the character U+00B5 <del>cannot be represented in the 
encoding used</del><ins>lacks representation in the execution character set</ins> for <code>charT</code>, the 
unit suffix <code>"us"</code> is used instead of <code>"&micro;s"</code>. <ins>If <code>"&micro;s"</code> is used but 
the implementation's native character set lacks representation for U+00B5 and the stream is associated 
with a terminal or console, or if the stream is imbued with a <code>std::codecvt</code> facet that lacks 
conversion support for the character, then the result is unspecified.</ins>
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>

</ol>
</blockquote>

<p><i>[2019-11-12; Tom Honermann improves wording]</i></p>

<p><i>[2020-02 Status to Immediate on Thursday night in Prague.]</i></p>



<p id="res-3314"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4835">N4835</a>.</p>

<ol>
<li><p>Modify 30.5.11 <a href="https://wg21.link/time.duration.io">[time.duration.io]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class charT, class traits, class Rep, class Period>
  basic_ostream&lt;charT, traits&gt;&amp;
    operator&lt;&lt;(basic_ostream&lt;charT, traits&gt;&amp; os, const duration&lt;Rep, Period&gt;&amp; d);
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-3- The units suffix depends on the type <code>Period::type</code> as follows:
<ol style="list-style-type: none">
<li><p>[&hellip;]</p></li>
<li><p>(3.5) &mdash; Otherwise, if <code>Period::type</code> is <code>micro</code>, <ins>it is implementation-defined 
whether</ins> the suffix is <code>"&micro;s"</code> (<code>"\u00b5\u0073"</code>) <ins>or <code>"us"</code></ins>.</p></li>
<li><p>[&hellip;]</p></li>
</ol>
<p/>
[&hellip;]
<p/>
<del>-4- If <code>Period::type</code> is <code>micro</code>, but the character U+00B5 cannot be represented in the 
encoding used for <code>charT</code>, the unit suffix <code>"us"</code> is used instead of <code>"&micro;s"</code>.</del>
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>

</ol>




</body>
</html>
