<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2943: Problematic specification of the wide version of basic_filebuf::open</title>
<meta property="og:title" content="Issue 2943: Problematic specification of the wide version of basic_filebuf::open">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2943.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="2943"><a href="lwg-defects.html#2943">2943</a>. Problematic specification of the wide version of <code>basic_filebuf::open</code></h3>
<p><b>Section:</b> 31.10.3.4 <a href="https://wg21.link/filebuf.members">[filebuf.members]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2017-03-09 <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#filebuf.members">issues</a> in [filebuf.members].</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>
LWG <a href="lwg-defects.html#2676" title="Provide filesystem::path overloads for File-based streams (Status: C++17)">2676</a><sup><a href="https://cplusplus.github.io/LWG/issue2676" title="Latest snapshot">(i)</a></sup> specified <code>basic_filebuf::open(const std::filesystem::path::value_type* s, ios_base::openmode mode)</code> 
by simply reusing the specification for the <code>const char*</code> overload, but that specification is incorrect for the wide overload: 
it says that <code>s</code> is an NTBS &mdash; a null-terminated byte string &mdash; which it isn't. Moreover, it specifies that 
the file is opened as if by calling <code>fopen(s, modstr)</code>, but that call is ill-formed if <code>s</code> isn't a <code>const char*</code>.
</p>

<p><i>[2017-07 Toronto Wed Issue Prioritization]</i></p>

<p>Priority 2</p>

<p><i>[2017-11 Albuquerque Wednesday issue processing]</i></p>

<p>Status to Open; Jonathan to provide wording.</p>

<p><i>[2018-01-16; Jonathan and Tim Song provide wording]</i></p>

<p>
We'll have to ask the Microsoft guys if "as by a call to <code>fopen</code>" is OK for them. There are 
paths that can be represented as a wide character string that can't reliably be converted to narrow 
characters (because they become dependent on the current codepage, or some other Windows nonsense) 
so they definitely won't use <code>fopen</code>. But as long as they call something that behaves like 
it (which should allow <code>_fwopen</code>), I think they'll still meet the spirit of the wording.
</p>

<p><i>[2018-08-14; Marshall corrects a grammar nit in the P/R]</i></p>

<p>The Microsoft guys note that "as by a call to <code>fopen</code>" is OK by them.</p>

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

<ol>
<li><p>Edit 31.10.3.4 <a href="https://wg21.link/filebuf.members">[filebuf.members]</a> as indicated:</p>
<blockquote>
<pre>
basic_filebuf* open(const char* s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path::value_type* s,
                    ios_base::openmode mode); <i>// wide systems only; see 31.10.1 <a href="https://wg21.link/fstream.syn">[fstream.syn]</a></i>
</pre>
<blockquote>
<p>
<ins>-?- <i>Requires:</i> <code>s</code> shall point to a NTCTS (3.36 <a href="https://wg21.link/defns.ntcts">[defns.ntcts]</a>).</ins>
<p/>
-2- <i>Effects:</i> If <code>is_open() != false</code>, returns a null pointer. Otherwise, initializes the 
<code>filebuf</code> as required. It then opens <ins>the file to which <code>s</code> resolves, if possible, as 
if by a call to <code>fopen</code> with the second argument</ins><del>a file, if possible, whose name is the 
<span style="font-variant:small-caps">ntbs</span> <code>s</code> (as if by calling <code>fopen(s, modstr))</code>. 
The <span style="font-variant:small-caps">ntbs</span> <code>modstr</code> is</del> determined from 
<code>mode &amp; ~ios_base::ate</code> as indicated in Table 117. If <code>mode</code> is not some combination 
of flags shown in the table then the open fails.
<p/>
-3- If the open operation succeeds and <code>(mode &amp; ios_base::ate) != 0</code>, positions the file to 
the end (as if by calling <code>fseek(file, 0, SEEK_END)</code><ins>, where <code>file</code> is the pointer 
returned by calling <code>fopen</code></ins>).(footnote 330)
<p/>
-4- If the repositioning operation fails, calls <code>close()</code> and returns a null pointer to indicate failure.
<p/>
-5- <i>Returns:</i> <code>this</code> if successful, a null pointer otherwise.
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2018-08-23 Batavia Issues processing]</i></p>

<p>Adopted after changing 'Requires' -> 'Expects' in the P/R.</p>
<p><i>[2018-11, Adopted in San Diego]</i></p>



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

<ol>
<li><p>Edit 31.10.3.4 <a href="https://wg21.link/filebuf.members">[filebuf.members]</a> as indicated:</p>
<blockquote>
<pre>
basic_filebuf* open(const char* s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path::value_type* s,
                    ios_base::openmode mode); <i>// wide systems only; see 31.10.1 <a href="https://wg21.link/fstream.syn">[fstream.syn]</a></i>
</pre>
<blockquote>
<p>
<ins>-?- <i>Expects:</i> <code>s</code> shall point to a NTCTS (3.36 <a href="https://wg21.link/defns.ntcts">[defns.ntcts]</a>).</ins>
<p/>
-2- <i>Effects:</i> If <code>is_open() != false</code>, returns a null pointer. Otherwise, initializes the 
<code>filebuf</code> as required. It then opens <ins>the file to which <code>s</code> resolves, if possible, as 
if by a call to <code>fopen</code> with the second argument</ins><del>a file, if possible, whose name is the 
<span style="font-variant:small-caps">ntbs</span> <code>s</code> (as if by calling <code>fopen(s, modstr))</code>. 
The <span style="font-variant:small-caps">ntbs</span> <code>modstr</code> is</del> determined from 
<code>mode &amp; ~ios_base::ate</code> as indicated in Table 117. If <code>mode</code> is not some combination 
of flags shown in the table then the open fails.
<p/>
-3- If the open operation succeeds and <code>(mode &amp; ios_base::ate) != 0</code>, positions the file to 
the end (as if by calling <code>fseek(file, 0, SEEK_END)</code><ins>, where <code>file</code> is the pointer 
returned by calling <code>fopen</code></ins>).(footnote 330)
<p/>
-4- If the repositioning operation fails, calls <code>close()</code> and returns a null pointer to indicate failure.
<p/>
-5- <i>Returns:</i> <code>this</code> if successful, a null pointer otherwise.
</p>
</blockquote>
</blockquote>
</li>
</ol>







</body>
</html>
