<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4192: &sect;[ios.base.cons] ios_base members may not have indeterminate values after construction</title>
<meta property="og:title" content="Issue 4192: &sect;[ios.base.cons] ios_base members may not have indeterminate values after construction">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4192.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="4192"><a href="lwg-active.html#4192">4192</a>. &sect;[ios.base.cons] <code class='backtick'>ios_base</code> members may not have indeterminate values after construction</h3>
<p><b>Section:</b> 31.5.2.8 <a href="https://wg21.link/ios.base.cons">[ios.base.cons]</a>, 31.5.2.4 <a href="https://wg21.link/ios.base.locales">[ios.base.locales]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> S. B. Tam <b>Opened:</b> 2025-01-12 <b>Last modified:</b> 2025-02-07</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#ios.base.cons">issues</a> in [ios.base.cons].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
31.5.2.8 <a href="https://wg21.link/ios.base.cons">[ios.base.cons]</a> specifies that
</p>
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
<p>
Each <code class='backtick'>ios_base</code> member has an indeterminate value after construction.
</p>
</blockquote>
<p>
However
</p>
<ul>
<li><p>If the <code class='backtick'>ios_base</code> object has static storage duration, the members would have been zero-initialized.</p></li>
<li><p>If the <code class='backtick'>ios_base</code> object has automatic storage duration, the members would have erroneous values.</p></li>
</ul>
<p>
In either case, the constructor cannot cause the members to have indeterminate values after construction.
<p/>
A related problem is that 31.5.2.4 <a href="https://wg21.link/ios.base.locales">[ios.base.locales]</a> requires <code class='backtick'>ios_base::getloc</code> to return:
</p>
<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;">
<p>
If no locale has been imbued, a copy of the global C++ locale, <code class='backtick'>locale()</code>, in effect at the time of construction.
</p>
</blockquote>
<p>
However, according to 31.5.2.8 <a href="https://wg21.link/ios.base.cons">[ios.base.cons]</a>, the corresponding member is not initialized 
until <code class='backtick'>basic_ios::init</code> is called.
</p>

<p><i>[2025-02-07; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>
<p>
"First part is NAD, can use e.g. placement new to force indeterminate values,
and it's not observable by well-defined progams anyway."
</p>



<p id="res-4192"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N5001" title=" Working Draft, Programming Languages — C++">N5001</a>.
</p>

<ol>

<li><p>Modify 31.5.2.4 <a href="https://wg21.link/ios.base.locales">[ios.base.locales]</a> as indicated:</p>

<blockquote>
<pre>
ios_base();
</pre>
<blockquote><p>
-1- <i>Effects</i>: Each <code class='backtick'>ios_base</code> member has an <ins>unspecified (possibly</ins> indeterminate <ins>or erroneous)</ins> 
value after construction. The object's members shall be initialized by calling <code class='backtick'>basic_ios::init</code> before the object's 
first use or before it is destroyed, whichever comes first; otherwise the behavior is undefined.
</p></blockquote>
</blockquote>
</li>

<li><p>Modify 31.5.2.8 <a href="https://wg21.link/ios.base.cons">[ios.base.cons]</a> as indicated:</p>

<blockquote>
<pre>
locale getloc() const;
</pre>
<blockquote><p>
-4- <i>Returns</i>: If no locale has been imbued, a copy of the global C++ locale, <code class='backtick'>locale()</code>, 
in effect at the time of <del>construction</del><ins>the last <code class='backtick'>basic_ios::init</code> call on the current 
object</ins>. Otherwise, returns the imbued locale, to be used to perform locale-dependent 
input and output operations.
</p></blockquote>
</blockquote>
</li>
</ol>






</body>
</html>
