<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3131: addressof all the things</title>
<meta property="og:title" content="Issue 3131: addressof all the things">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3131.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="3131"><a href="lwg-defects.html#3131">3131</a>. <code>addressof</code> all the things</h3>
<p><b>Section:</b> 30.13 <a href="https://wg21.link/time.parse">[time.parse]</a>, 27.4.3.8.1 <a href="https://wg21.link/string.accessors">[string.accessors]</a>, 27.3.3 <a href="https://wg21.link/string.view.template">[string.view.template]</a>, 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a>, 24.3.5.4 <a href="https://wg21.link/output.iterators">[output.iterators]</a>, 24.3.5.6 <a href="https://wg21.link/bidirectional.iterators">[bidirectional.iterators]</a>, 28.6.6 <a href="https://wg21.link/re.traits">[re.traits]</a>, 28.6.11.1 <a href="https://wg21.link/re.regiter">[re.regiter]</a>, 32.6.5.2 <a href="https://wg21.link/thread.lock.guard">[thread.lock.guard]</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 other</b> <a href="lwg-index-open.html#time.parse">active issues</a> in [time.parse].</p>
<p><b>View all other</b> <a href="lwg-index.html#time.parse">issues</a> in [time.parse].</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>
Some additional instances where the library specification applies unary
operator <code>&amp;</code> when it should use <code>addressof</code>.
</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-3131"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4750">N4750</a>.
</p>
<blockquote class="note">
<p>
[<i>Drafting note:</i> Two uses of <code>&amp;</code> in 24.5.1 <a href="https://wg21.link/reverse.iterators">[reverse.iterators]</a> are not included in 
the wording below because the entire sentence is slated to be removed by a revision of <a href="https://wg21.link/p0896">P0896</a>,
the One Ranges Proposal.]
</p>
</blockquote>
<ol>
<li>
<p>
Change 30.13 <a href="https://wg21.link/time.parse">[time.parse]</a> p4-5 as indicated:
</p>
<blockquote>
<pre>
template&lt;class charT, class traits, class Alloc, class Parsable&gt;
  <i>unspecified</i>
    parse(const basic_string&lt;charT, traits, Alloc&gt;&amp; fmt, Parsable&amp; tp,
          basic_string&lt;charT, traits, Alloc&gt;&amp; abbrev);
</pre>
<blockquote>
<p>
-4- <i>Remarks:</i> This function shall not participate in overload resolution unless
</p>
<blockquote>
<pre>
from_stream(declval&lt;basic_istream&lt;charT, traits&gt;&amp;&gt;(), fmt.c_str(), tp, <del>&amp;</del><ins>addressof(</ins>abbrev<ins>)</ins>)
</pre>
</blockquote>
<p>
is a valid expression.
<p/>
-5- <i>Returns:</i> A manipulator that, when extracted from a <code>basic_istream&lt;charT, traits&gt; is</code>,
calls <code>from_stream(is, fmt.c_str(), tp, <del>&amp;</del><ins>addressof(</ins>abbrev<ins>)</ins>)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 30.13 <a href="https://wg21.link/time.parse">[time.parse]</a> p8-9 as indicated:
</p>
<blockquote>
<pre>
template&lt;class charT, class traits, class Alloc, class Parsable&gt;
  <i>unspecified</i>
    parse(const basic_string&lt;charT, traits, Alloc&gt;&amp; fmt, Parsable&amp; tp,
          basic_string&lt;charT, traits, Alloc&gt;&amp; abbrev, minutes&amp; offset);
</pre>
<blockquote>
<p>
-8- <i>Remarks:</i> This function shall not participate in overload resolution unless
</p>
<blockquote>
<pre>
from_stream(declval&lt;basic_istream&lt;charT, traits&gt;&amp;&gt;(), fmt.c_str(), tp, <del>&amp;</del><ins>addressof(</ins>abbrev<ins>)</ins>, &amp;offset)
</pre>
</blockquote>
<p>
is a valid expression.
<p/>
-9- <i>Returns:</i> A manipulator that, when extracted from a <code>basic_istream&lt;charT, traits&gt; is</code>,
calls <code>from_stream(is, fmt.c_str(), tp, <del>&amp;</del><ins>addressof(</ins>abbrev<ins>)</ins>, &amp;offset)</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 27.4.3.8.1 <a href="https://wg21.link/string.accessors">[string.accessors]</a> p1 and p4 as indicated:
</p>
<blockquote>
<pre>
const charT* c_str() const noexcept;
const charT* data() const noexcept;
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> A pointer <code>p</code> such that <code>p + i == <del>&amp;</del><ins>addressof(</ins>operator[](i)<ins>)</ins></code>
for each <code>i</code> in <code>[0, size()]</code>.
<p/>
-2- <i>Complexity:</i> Constant time.
<p/>
-3- <i>Requires:</i> The program shall not alter any of the values stored in the character array.
</p>
</blockquote>
<pre>
charT* data() noexcept;
</pre>
<blockquote>
<p>
-4- <i>Returns:</i> A pointer <code>p</code> such that <code>p + i == <del>&amp;</del><ins>addressof(</ins>operator[](i)<ins>)</ins></code>
for each <code>i</code> in <code>[0, size()]</code>.
<p/>
-5- <i>Complexity:</i> Constant time.
<p/>
-6- <i>Requires:</i> The program shall not alter the value stored at <code>p + size()</code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 27.3.3.4 <a href="https://wg21.link/string.view.iterators">[string.view.iterators]</a> p4 as indicated:
</p>
<blockquote>
<pre>
constexpr const_iterator begin() const noexcept;
constexpr const_iterator cbegin() const noexcept;
</pre>
<blockquote>
<p>
-4- <i>Returns:</i> An iterator such that
<p/>
(4.1) &mdash; if <code>!empty()</code>, <code><del>&amp;</del><ins>addressof(</ins>*begin()<ins>)</ins> == data_</code>,
<p/>
(4.2) &mdash; otherwise, an unspecified value such that <code>[begin(), end())</code> is a valid range.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 27.3.3.8 <a href="https://wg21.link/string.view.ops">[string.view.ops]</a> p21 and p24 as indicated:
</p>
<blockquote>
<pre>
constexpr bool starts_with(charT x) const noexcept;
</pre>
<blockquote>
<p>
-21- <i>Effects:</i> Equivalent to: <code>return starts_with(basic_string_view(<del>&amp;</del><ins>addressof(</ins>x<ins>)</ins>, 1));</code>
</p>
</blockquote>
<p>[&hellip;]</p>
<pre>
constexpr bool ends_with(charT x) const noexcept;
</pre>
<blockquote>
<p>
-24- <i>Effects:</i> Equivalent to: <code>return ends_with(basic_string_view(<del>&amp;</del><ins>addressof(</ins>x<ins>)</ins>, 1));</code>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 27.3.3.9 <a href="https://wg21.link/string.view.find">[string.view.find]</a> p5 as indicated:
</p>
<blockquote>
<p>
-5- Each member function of the form
</p>
<blockquote>
<pre>
constexpr <i>return-type</i> <i>F</i>(charT c, size_type pos);
</pre>
</blockquote>
<p>
is equivalent to <code>return <i>F</i>(basic_string_view(<del>&amp;</del><ins>addressof(</ins>c<ins>)</ins>, 1), pos);</code>
</p>
</blockquote>
</li>

<li>
<p>
Edit 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a>, Table 77 &mdash; "Container requirements", as indicated:
</p>
<blockquote>
<table border="1">
<caption>Table 77 &mdash; Container requirements</caption>
<tr style="text-align:center">
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion/note<br/>pre/post-condition</th>
<th>Complexity</th>
</tr>
<tr>
<td colspan="5" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code><del>(&amp;a)-&gt;</del><ins>a.</ins>~X()</code>
</td>
<td>
<code>void</code>
</td>
<td></td>
<td>
the destructor is applied to every element of <code>a</code>; any memory obtained is deallocated.
</td>
<td>
linear
</td>
</tr>
<tr>
<td colspan="5" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
</blockquote>
</li>

<li>
<p>
Edit 24.3.5.4 <a href="https://wg21.link/output.iterators">[output.iterators]</a>, Table 90 &mdash; "Output iterator requirements (in addition to Iterator)", as indicated:
</p>
<blockquote>
<table border="1">
<caption>Table 90 &mdash; Output iterator requirements (in addition to Iterator)</caption>
<tr style="text-align:center">
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion/note<br/>pre/post-condition</th>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
<tr>
<td>
<code>++r</code>
</td>
<td>
<code>X&amp;</code>
</td>
<td></td>
<td>
<code><del>&amp;</del><ins>addressof(</ins>r<ins>)</ins> == <del>&amp;</del><ins>addressof(</ins>++r<ins>)</ins></code>.
<br/>[&hellip;]
</td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
</blockquote>
</li>

<li>
<p>
Edit 24.3.5.6 <a href="https://wg21.link/bidirectional.iterators">[bidirectional.iterators]</a>, Table 92 &mdash; "Bidirectional iterator requirements (in addition to forward iterator)", as indicated:
</p>
<blockquote>
<table border="1">
<caption>Table 92 &mdash; Bidirectional iterator requirements (in addition to forward iterator)</caption>
<tr style="text-align:center">
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion/note<br/>pre/post-condition</th>
</tr>
<tr>
<td>
<code>--r</code>
</td>
<td>
<code>X&amp;</code>
</td>
<td></td>
<td>
[&hellip;]
<br/>
<code><del>&amp;</del><ins>addressof(</ins>r<ins>)</ins> == <del>&amp;</del><ins>addressof(</ins>--r<ins>)</ins></code>.
</td>
</tr>
<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>
</table>
</blockquote>
</li>
<li>
<p>
Change 28.6.6 <a href="https://wg21.link/re.traits">[re.traits]</a> p6 as indicated:
</p>
<blockquote>
<pre>
template&lt;class ForwardIterator&gt;
  string_type transform(ForwardIterator first, ForwardIterator last) const;
</pre>
<blockquote>
<p>
-6- <i>Effects:</i> As if by:
</p>
<blockquote>
<pre>
string_type str(first, last);
return use_facet&lt;collate&lt;charT&gt;&gt;(
  getloc()).transform(<del>&amp;*</del>str.<del>begin</del><ins>data</ins>(), <del>&amp;*</del>str.<del>begin</del><ins>data</ins>() + str.length());
</pre>
</blockquote>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 28.6.11.1.2 <a href="https://wg21.link/re.regiter.cnstr">[re.regiter.cnstr]</a> p2 as indicated:
</p>
<blockquote>
<pre>
regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
               const regex_type&amp; re,
               regex_constants::match_flag_type m = regex_constants::match_default);
</pre>
<blockquote>
<p>
-2- <i>Effects:</i> Initializes <code>begin</code> and <code>end</code> to <code>a</code> and <code>b</code>, respectively,
sets <code>pregex</code> to <code><del>&amp;</del><ins>addressof(</ins>re<ins>)</ins></code>, sets <code>flags</code> to <code>m</code>,
then calls <code>regex_search(begin, end, match, *pregex, flags)</code>. If this call returns <code>false</code>
the constructor sets <code>*this</code> to the end-of-sequence iterator.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 28.6.11.1.4 <a href="https://wg21.link/re.regiter.deref">[re.regiter.deref]</a> p2 as indicated:
</p>
<blockquote>
<pre>
const value_type* operator-&gt;() const;
</pre>
<blockquote>
<p>
-2- <i>Returns:</i> <code><del>&amp;</del><ins>addressof(</ins>match<ins>)</ins></code>.
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 32.6.5.2 <a href="https://wg21.link/thread.lock.guard">[thread.lock.guard]</a> p2-7 as indicated:
</p>
<blockquote>
<pre>
explicit lock_guard(mutex_type&amp; m);
</pre>
<blockquote>
<p>
-2- <i>Requires:</i> If <code>mutex_type</code> is not a recursive mutex, the calling thread does not own the mutex <code>m</code>.
<p/>
-3- <i>Effects:</i> <del>As if by</del><ins>Initializes <code>pm</code> with <code>m</code>. Calls</ins> <code>m.lock()</code>.
<p/>
<del>-4- <i>Postconditions:</i> <code>&amp;pm == &amp;m</code></del>
</p>
</blockquote>
<pre>
lock_guard(mutex_type&amp; m, adopt_lock_t);
</pre>
<blockquote>
<p>
-5- <i>Requires:</i> The calling thread owns the mutex <code>m</code>.
<p/>
-6- <del><i>Postconditions:</i> <code>&amp;pm == &amp;m</code></del><ins><i>Effects:</i> Initializes <code>pm</code> with <code>m</code>.</ins>
<p/>
-7- <i>Throws:</i> Nothing.
</p>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
