<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3130: &sect;[input.output] needs many addressof</title>
<meta property="og:title" content="Issue 3130: &sect;[input.output] needs many addressof">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3130.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="3130"><a href="lwg-defects.html#3130">3130</a>. &sect;[input.output] needs many <code>addressof</code></h3>
<p><b>Section:</b> 31 <a href="https://wg21.link/input.output">[input.output]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2018-06-30 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#input.output">issues</a> in [input.output].</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>
There are 27 instances of <code>&amp;sb</code> and one instance of <code>&amp;rhs</code> in 
Clause 31 <a href="https://wg21.link/input.output">[input.output]</a>, each of which needs to use <code>addressof</code> because
the operand has a user-provided template type parameter as an associated class and so
the use of unary <code>&amp;</code> is subject to ADL hijacking.
</p>

<p><i>[2018-07-20 Status to Tentatively Ready after five positive votes on the reflector.]</i></p>

<p><i>[2018-11, Adopted in San Diego]</i></p>



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

<ol>
<li>
<p>
Change 31.5.4.3 <a href="https://wg21.link/basic.ios.members">[basic.ios.members]</a> p16 as indicated:
</p>
<blockquote>
<pre>
basic_ios&amp; copyfmt(const basic_ios&amp; rhs);
</pre>
<blockquote>
<p>
-16- <i>Effects:</i> If <code>(this == <del>&amp;</del><ins>addressof(</ins>rhs<ins>)</ins>)</code> 
does nothing. [&hellip;]
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.8.3.2 <a href="https://wg21.link/istringstream.cons">[istringstream.cons]</a> as indicated:
</p>
<blockquote>
<pre>
explicit basic_istringstream(ios_base::openmode which);
</pre>
<blockquote>
<p>
-1- <i>Effects:</i> Constructs an object of class <code>basic_istringstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_istream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.2 <a href="https://wg21.link/istream">[istream]</a>) and initializing <code>sb</code> with 
<code>basic_stringbuf&lt;charT, traits, Allocator&gt;(which | ios_base::in)</code> (31.8.2.2 <a href="https://wg21.link/stringbuf.cons">[stringbuf.cons]</a>).
</p>
</blockquote>
<pre>
explicit basic_istringstream(
  const basic_string&lt;charT, traits, Allocator&gt;&amp; str,
  ios_base::openmode which = ios_base::in);
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> Constructs an object of class <code>basic_istringstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_istream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.2 <a href="https://wg21.link/istream">[istream]</a>) and initializing <code>sb</code> with 
<code>basic_stringbuf&lt;charT, traits, Allocator&gt;(str, which | ios_base::in)</code> (31.8.2.2 <a href="https://wg21.link/stringbuf.cons">[stringbuf.cons]</a>).
</p>
</blockquote>
<pre>
basic_istringstream(basic_istringstream&amp;&amp; rhs);
</pre>
<blockquote>
<p>
-3- <i>Effects:</i> Move constructs from the rvalue <code>rhs</code>. This is accomplished
by move constructing the base class, and the contained <code>basic_stringbuf</code>.
Next <code>basic_istream&lt;charT, traits&gt;::set_rdbuf(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
is called to install the contained <code>basic_stringbuf</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.8.3.4 <a href="https://wg21.link/istringstream.members">[istringstream.members]</a> p1 as indicated:
</p>
<blockquote>
<pre>
basic_stringbuf&lt;charT, traits, Allocator&gt;* rdbuf() const;
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>const_cast&lt;basic_stringbuf&lt;charT, traits, Allocator&gt;*&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.8.4.2 <a href="https://wg21.link/ostringstream.cons">[ostringstream.cons]</a> as indicated:
</p>
<blockquote>
<pre>
explicit basic_ostringstream(ios_base::openmode which);
</pre>
<blockquote>
<p>
-1- <i>Effects:</i> Constructs an object of class <code>basic_ostringstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_ostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.6.2 <a href="https://wg21.link/ostream">[ostream]</a>) and initializing <code>sb</code> with 
<code>basic_stringbuf&lt;charT, traits, Allocator&gt;(which | ios_base::out)</code> (31.8.2.2 <a href="https://wg21.link/stringbuf.cons">[stringbuf.cons]</a>).
</p>
</blockquote>
<pre>
explicit basic_ostringstream(
  const basic_string&lt;charT, traits, Allocator&gt;&amp; str,
  ios_base::openmode which = ios_base::out);
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> Constructs an object of class <code>basic_ostringstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_ostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.6.2 <a href="https://wg21.link/ostream">[ostream]</a>) and initializing <code>sb</code> with
<code>basic_stringbuf&lt;charT, traits, Allocator&gt;(str, which | ios_base::out)</code> (31.8.2.2 <a href="https://wg21.link/stringbuf.cons">[stringbuf.cons]</a>).
</p>
</blockquote>
<pre>
basic_ostringstream(basic_ostringstream&amp;&amp; rhs);
</pre>
<blockquote>
<p>
-3- <i>Effects:</i> Move constructs from the rvalue <code>rhs</code>. This is accomplished 
by move constructing the base class, and the contained <code>basic_stringbuf</code>. 
Next <code>basic_ostream&lt;charT, traits&gt;::set_rdbuf(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
is called to install the contained <code>basic_stringbuf</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.8.4.4 <a href="https://wg21.link/ostringstream.members">[ostringstream.members]</a> p1 as indicated:
</p>
<blockquote>
<pre>
basic_stringbuf&lt;charT, traits, Allocator&gt;* rdbuf() const;
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>const_cast&lt;basic_stringbuf&lt;charT, traits, Allocator&gt;*&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.8.5.2 <a href="https://wg21.link/stringstream.cons">[stringstream.cons]</a> as indicated:
</p>
<blockquote>
<pre>
explicit basic_stringstream(ios_base::openmode which);
</pre>
<blockquote>
<p>
-1- <i>Effects:</i> Constructs an object of class <code>basic_stringstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_iostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.7.2 <a href="https://wg21.link/iostream.cons">[iostream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_stringbuf&lt;charT, traits, Allocator&gt;(which)</code>.
</p>
</blockquote>
<pre>
explicit basic_stringstream(
  const basic_string&lt;charT, traits, Allocator&gt;&amp; str,
  ios_base::openmode which = ios_base::out | ios_base::in);
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> Constructs an object of class <code>basic_stringstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_iostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.7.2 <a href="https://wg21.link/iostream.cons">[iostream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_stringbuf&lt;charT, traits, Allocator&gt;(str, which)</code>.
</p>
</blockquote>
<pre>
basic_stringstream(basic_stringstream&amp;&amp; rhs);
</pre>
<blockquote>
<p>
-3- <i>Effects:</i> Move constructs from the rvalue <code>rhs</code>. This is accomplished 
by move constructing the base class, and the contained <code>basic_stringbuf</code>. 
Next <code>basic_istream&lt;charT, traits&gt;::set_rdbuf(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
is called to install the contained <code>basic_stringbuf</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.8.5.4 <a href="https://wg21.link/stringstream.members">[stringstream.members]</a> p1 as indicated:
</p>
<blockquote>
<pre>
basic_stringbuf&lt;charT, traits, Allocator&gt;* rdbuf() const;
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>const_cast&lt;basic_stringbuf&lt;charT, traits, Allocator&gt;*&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code><ins>.</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.10.4.2 <a href="https://wg21.link/ifstream.cons">[ifstream.cons]</a> as indicated:
</p>
<blockquote>
<pre>
basic_ifstream();
</pre>
<blockquote>
<p>
-1- <i>Effects:</i> Constructs an object of class <code>basic_ifstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_istream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.2.2 <a href="https://wg21.link/istream.cons">[istream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_filebuf&lt;charT, traits&gt;()</code> (31.10.3.2 <a href="https://wg21.link/filebuf.cons">[filebuf.cons]</a>).
</p>
</blockquote>
<pre>
explicit basic_ifstream(const char* s,
                        ios_base::openmode mode = ios_base::in);
explicit basic_ifstream(const filesystem::path::value_type* s,
                        ios_base::openmode mode = ios_base::in);  // wide systems only; see 31.10.1 <a href="https://wg21.link/fstream.syn">[fstream.syn]</a>
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> Constructs an object of class <code>basic_ifstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_istream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.2.2 <a href="https://wg21.link/istream.cons">[istream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_filebuf&lt;charT, traits&gt;()</code> (31.10.3.2 <a href="https://wg21.link/filebuf.cons">[filebuf.cons]</a>), then calls 
<code>rdbuf()-&gt;open(s, mode | ios_base::in)</code>. If that function returns a null pointer, calls <code>setstate(failbit)</code>.
</p>
</blockquote>
<p>[&hellip;]</p>
<pre>
basic_ifstream(basic_ifstream&amp;&amp; rhs);
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Move constructs from the rvalue <code>rhs</code>. This is accomplished 
by move constructing the base class, and the contained <code>basic_filebuf</code>. 
Next <code>basic_istream&lt;charT, traits&gt;::set_rdbuf(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
is called to install the contained <code>basic_filebuf</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.10.4.4 <a href="https://wg21.link/ifstream.members">[ifstream.members]</a> p1 as indicated:
</p>
<blockquote>
<pre>
basic_filebuf&lt;charT, traits&gt;* rdbuf() const;
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>const_cast&lt;basic_filebuf&lt;charT, traits&gt;*&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.10.5.2 <a href="https://wg21.link/ofstream.cons">[ofstream.cons]</a> as indicated:
</p>
<blockquote>
<pre>
basic_ofstream();
</pre>
<blockquote>
<p>
-1- <i>Effects:</i> Constructs an object of class <code>basic_ofstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_ostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.6.2.2 <a href="https://wg21.link/ostream.cons">[ostream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_filebuf&lt;charT, traits&gt;()</code> (31.10.3.2 <a href="https://wg21.link/filebuf.cons">[filebuf.cons]</a>).
</p>
</blockquote>
<pre>
explicit basic_ofstream(const char* s,
                        ios_base::openmode mode = ios_base::out);
explicit basic_ofstream(const filesystem::path::value_type* s,
                        ios_base::openmode mode = ios_base::out);  // wide systems only; see 31.10.1 <a href="https://wg21.link/fstream.syn">[fstream.syn]</a>
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> Constructs an object of class <code>basic_ofstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_ostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.6.2.2 <a href="https://wg21.link/ostream.cons">[ostream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_filebuf&lt;charT, traits&gt;()</code> (31.10.3.2 <a href="https://wg21.link/filebuf.cons">[filebuf.cons]</a>), then calls 
<code>rdbuf()-&gt;open(s, mode | ios_base::out)</code>. If that function returns a null pointer, calls <code>setstate(failbit)</code>.
</p>
</blockquote>
<p>[&hellip;]</p>
<pre>
basic_ofstream(basic_ofstream&amp;&amp; rhs);
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Move constructs from the rvalue <code>rhs</code>. This is accomplished 
by move constructing the base class, and the contained <code>basic_filebuf</code>. 
Next <code>basic_ostream&lt;charT, traits&gt;::set_rdbuf(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
is called to install the contained <code>basic_filebuf</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.10.5.4 <a href="https://wg21.link/ofstream.members">[ofstream.members]</a> p1 as indicated:
</p>
<blockquote>
<pre>
basic_filebuf&lt;charT, traits&gt;* rdbuf() const;
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>const_cast&lt;basic_filebuf&lt;charT, traits&gt;*&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.10.6.2 <a href="https://wg21.link/fstream.cons">[fstream.cons]</a> as indicated:
</p>
<blockquote>
<pre>
basic_fstream();
</pre>
<blockquote>
<p>
-1- <i>Effects:</i> Constructs an object of class <code>basic_fstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_iostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.7.2 <a href="https://wg21.link/iostream.cons">[iostream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_filebuf&lt;charT, traits&gt;()</code>.
</p>
</blockquote>
<pre>
explicit basic_fstream(
  const char* s,
  ios_base::openmode mode = ios_base::in | ios_base::out);
explicit basic_fstream(
  const filesystem::path::value_type* s,
  ios_base::openmode mode = ios_base::in | ios_base::out);  // wide systems only; see 31.10.1 <a href="https://wg21.link/fstream.syn">[fstream.syn]</a>
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> Constructs an object of class <code>basic_fstream&lt;charT, traits&gt;</code>,
initializing the base class with <code>basic_iostream&lt;charT, traits&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
(31.7.5.7.2 <a href="https://wg21.link/iostream.cons">[iostream.cons]</a>) and initializing <code>sb</code> with 
<code>basic_filebuf&lt;charT, traits&gt;()</code>, then calls <code>rdbuf()-&gt;open(s, mode)</code>.
If that function returns a null pointer, calls <code>setstate(failbit)</code>.
</p>
</blockquote>
<p>[&hellip;]</p>
<pre>
basic_fstream(basic_fstream&amp;&amp; rhs);
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Move constructs from the rvalue <code>rhs</code>. This is accomplished 
by move constructing the base class, and the contained <code>basic_filebuf</code>. 
Next <code>basic_istream&lt;charT, traits&gt;::set_rdbuf(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>
is called to install the contained <code>basic_filebuf</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.10.6.4 <a href="https://wg21.link/fstream.members">[fstream.members]</a> p1 as indicated:
</p>
<blockquote>
<pre>
basic_filebuf&lt;charT, traits&gt;* rdbuf() const;
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>const_cast&lt;basic_filebuf&lt;charT, traits&gt;*&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 31.11.3.1 <a href="https://wg21.link/syncstream.osyncstream.overview">[syncstream.osyncstream.overview]</a>, class template <code>basic_osyncstream</code> synopsis, as indicated:
</p>
<blockquote class="note">
<p>
[<i>Drafting note</i>: The text shown below assumes the application of the proposed resolution of issue <a href="lwg-defects.html#3127" title="basic_osyncstream::rdbuf needs a const_cast (Status: C++20)">3127</a><sup><a href="https://cplusplus.github.io/LWG/issue3127" title="Latest snapshot">(i)</a></sup>.]
</p>
</blockquote>
<blockquote>
<pre>
namespace std {
  template&lt;class charT, class traits, class Allocator&gt;
  class basic_osyncstream : public basic_ostream&lt;charT, traits&gt; {
  public:
    [&hellip;]

    // 31.11.3.3 <a href="https://wg21.link/syncstream.osyncstream.members">[syncstream.osyncstream.members]</a>, member functions
    void emit();
    streambuf_type* get_wrapped() const noexcept;
    syncbuf_type* rdbuf() const noexcept { return const_cast&lt;syncbuf_type*&gt;(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>); }
    [&hellip;]
  };
}
</pre>
</blockquote>
</li>

<li>
<p>
Change 31.11.3.2 <a href="https://wg21.link/syncstream.osyncstream.cons">[syncstream.osyncstream.cons]</a> p1 and p4 as indicated:
</p>
<blockquote>
<pre>
basic_osyncstream(streambuf_type* buf, const Allocator&amp; allocator);
</pre>
<blockquote>
<p>
-1- <i>Effects:</i> Initializes <code>sb</code> from <code>buf</code> and <code>allocator</code>. 
Initializes the base class with <code>basic_ostream<ins>&lt;charT, traits&gt;</ins>(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>.
<p/>
-2- [&hellip;]
<p/>
-3- [&hellip;]
</p>
</blockquote>
<pre>
basic_osyncstream(basic_osyncstream&amp;&amp; other) noexcept;
</pre>
<blockquote>
<p>
-4- <i>Effects:</i> Move constructs the base class and <code>sb</code> from the corresponding subobjects of <code>other</code>,
and calls <code>basic_ostream&lt;charT, traits&gt;::set_rdbuf(<del>&amp;</del><ins>addressof(</ins>sb<ins>)</ins>)</code>.
<p/>
-5- [&hellip;]
</p>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
