<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 182: Ambiguous references to size_t</title>
<meta property="og:title" content="Issue 182: Ambiguous references to size_t">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue182.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#CD1">CD1</a> status.</em></p>
<h3 id="182"><a href="lwg-defects.html#182">182</a>. Ambiguous references to size_t</h3>
<p><b>Section:</b> 16 <a href="https://wg21.link/library">[library]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Al Stevens <b>Opened:</b> 1999-08-15 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#library">active issues</a> in [library].</p>
<p><b>View all other</b> <a href="lwg-index.html#library">issues</a> in [library].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>Many references to <code> size_t</code> throughout the document
omit the <code> std::</code> namespace qualification.</p> <p>For
example, 16.4.5.6 <a href="https://wg21.link/replacement.functions">[replacement.functions]</a> paragraph 2:</p>
<blockquote>
<pre> operator new(size_t)
 operator new(size_t, const std::nothrow_t&amp;)
 operator new[](size_t)
 operator new[](size_t, const std::nothrow_t&amp;)</pre>
</blockquote>


<p id="res-182"><b>Proposed resolution:</b></p>
<p>   In 16.4.5.6 <a href="https://wg21.link/replacement.functions">[replacement.functions]</a> paragraph 2: replace:</p>
<blockquote>
<p><code>     - operator new(size_t)<br/>
     - operator new(size_t, const std::nothrow_t&amp;)<br/>
     - operator new[](size_t)<br/>
     - operator new[](size_t, const std::nothrow_t&amp;)</code></p>
</blockquote>
<p>    by:</p>
<blockquote>
<pre>- operator new(std::size_t)
- operator new(std::size_t, const std::nothrow_t&amp;)
- operator new[](std::size_t)
- operator new[](std::size_t, const std::nothrow_t&amp;)</pre>
</blockquote>
<p>In [lib.allocator.requirements] 20.1.5, paragraph 4: replace:</p>
<blockquote>
  <p>The typedef members pointer, const_pointer, size_type, and difference_type
  are required to be T*, T const*, size_t, and ptrdiff_t, respectively.</p>
</blockquote>
<p>&nbsp;by:</p>
<blockquote>
  <p>The typedef members pointer, const_pointer, size_type, and difference_type
  are required to be T*, T const*, std::size_t, and std::ptrdiff_t,
  respectively.</p>
</blockquote>
<p>In [lib.allocator.members] 20.4.1.1, paragraphs 3 and 6: replace:</p>
<blockquote>
  <p>3 Notes: Uses ::operator new(size_t) (18.4.1).</p>
  <p>6 Note: the storage is obtained by calling ::operator new(size_t), but it
  is unspecified when or how often this function is called. The use of hint is
  unspecified, but intended as an aid to locality if an implementation so
  desires.</p>
</blockquote>
<p>by:</p>
<blockquote>
  <p>3 Notes: Uses ::operator new(std::size_t) (18.4.1).</p>
  <p>6 Note: the storage is obtained by calling ::operator new(std::size_t), but
  it is unspecified when or how often this function is called. The use of hint
  is unspecified, but intended as an aid to locality if an implementation so
  desires.</p>
</blockquote>
<p>In [lib.char.traits.require] 21.1.1, paragraph 1: replace:</p>
<blockquote>
  <p>In Table 37, X denotes a Traits class defining types and functions for the
  character container type CharT; c and d denote values of type CharT; p and q
  denote values of type const CharT*; s denotes a value of type CharT*; n, i and
  j denote values of type size_t; e and f denote values of type X::int_type; pos
  denotes a value of type X::pos_type; and state denotes a value of type X::state_type.</p>
</blockquote>
<p>by:</p>
<blockquote>
  <p>In Table 37, X denotes a Traits class defining types and functions for the
  character container type CharT; c and d denote values of type CharT; p and q
  denote values of type const CharT*; s denotes a value of type CharT*; n, i and
  j denote values of type std::size_t; e and f denote values of type X::int_type;
  pos denotes a value of type X::pos_type; and state denotes a value of type X::state_type.</p>
</blockquote>
<p>In [lib.char.traits.require] 21.1.1, table 37: replace the return type of
X::length(p): &quot;size_t&quot; by &quot;std::size_t&quot;.</p>
<p>   In [lib.std.iterator.tags] 24.3.3, paragraph 2:    replace:<br/>
&nbsp;&nbsp;&nbsp; typedef ptrdiff_t difference_type;<br/>
    by:<br/>
&nbsp;&nbsp;&nbsp; typedef std::ptrdiff_t difference_type;</p>
<p>   In [lib.locale.ctype] 22.2.1.1 put namespace std { ...} around the declaration of    template &lt;class charT&gt; class ctype.<br/>
<br/>
   In [lib.iterator.traits] 24.3.1, paragraph 2    put namespace std { ...} around the declaration of:<br/>
<br/>
&nbsp;&nbsp;&nbsp; template&lt;class Iterator&gt; struct iterator_traits<br/>
&nbsp;&nbsp;&nbsp; template&lt;class T&gt; struct iterator_traits&lt;T*&gt;<br/>
&nbsp;&nbsp;&nbsp; template&lt;class T&gt; struct iterator_traits&lt;const T*&gt;</p>


<p><b>Rationale:</b></p>
<p>The LWG believes correcting names like <code>size_t</code> and
<code>ptrdiff_t</code> to <code>std::size_t</code> and <code>std::ptrdiff_t</code>
to be essentially editorial.  There there can't be another size_t or
ptrdiff_t meant anyway because, according to 16.4.5.3.5 <a href="https://wg21.link/extern.types">[extern.types]</a>,</p>

<blockquote><p>
For each type T from the Standard C library, the types ::T and std::T
are reserved to the implementation and, when defined, ::T shall be
identical to std::T.
</p></blockquote>

<p>The issue is treated as a Defect Report to make explicit the Project
Editor's authority to make this change.</p>

<p><i>[Post-Tokyo: Nico Josuttis provided the above wording at the
request of the LWG.]</i></p>


<p><i>[Toronto: This is tangentially related to issue <a href="lwg-defects.html#229" title="Unqualified references of other library entities (Status: CD1)">229</a><sup><a href="https://cplusplus.github.io/LWG/issue229" title="Latest snapshot">(i)</a></sup>, but only tangentially: the intent of this issue is to
address use of the name <code>size_t</code> in contexts outside of
namespace std, such as in the description of <code>::operator new</code>.
The proposed changes should be reviewed to make sure they are
correct.]</i></p>


<p><i>[pre-Copenhagen: Nico has reviewed the changes and believes
them to be correct.]</i></p>







</body>
</html>
