<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3170: is_always_equal added to std::allocator makes the standard library treat 
derived types as always equal</title>
<meta property="og:title" content="Issue 3170: is_always_equal added to std::allocator makes the standard library treat 
derived types as always equal">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3170.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++23">C++23</a> status.</em></p>
<h3 id="3170"><a href="lwg-defects.html#3170">3170</a>. <code>is_always_equal</code> added to <code>std::allocator</code> makes the standard library treat 
derived types as always equal</h3>
<p><b>Section:</b> 20.2.10 <a href="https://wg21.link/default.allocator">[default.allocator]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Billy O'Neal III <b>Opened:</b> 2018-11-29 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</p>
<p><b>View other</b> <a href="lwg-index-open.html#default.allocator">active issues</a> in [default.allocator].</p>
<p><b>View all other</b> <a href="lwg-index.html#default.allocator">issues</a> in [default.allocator].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
I (Billy O'Neal) attempted to change MSVC++'s standard library to avoid instantiating allocators' <code>operator==</code> 
for allocators that are declared <code>is_always_equal</code> to reduce the number of template instantiations emitted into .objs.
<p/>
In so doing I introduced an unrelated bug related to POCMA handling, but it brought my attention to 
<a href="https://github.com/boostorg/poly_collection/blob/5ed5d5e99336130783bdb33126d8629890235aed/test/test_utilities.hpp#L324">this 
allocator</a>. This allocator doesn't meet the allocator requirements because it is getting <code>std::allocator</code>'s 
<code>operator==</code> and <code>operator!=</code> which don't compare the root member. However, if this had been a conforming C++14 
allocator with its own <code>==</code> and <code>!=</code> we would still be treating it as <code>is_always_equal</code>, as it picks that 
up by deriving from <code>std::allocator</code>.
<p/>
<code>std::allocator</code> doesn't actually need <code>is_always_equal</code> because the defaults provided by <code>allocator_traits</code> 
will say <code>true_type</code> for it, since implementers don't make <code>std::allocator</code> stateful.
<p/>
Billy O'Neal thinks this is NAD on the grounds that we need to be able to add things or change the behavior of standard library types.
<p/>
Stephan T Lavavej thinks we should resolve this anyway because we don't know of an implementation for which this would change 
the default answer provided by <code>allocator_traits</code>.
</p>

<p><i>[2019-02 Priority set to 2 after reflector discussion]</i></p>


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

<ol>
<li><p>Modify 20.2.10 <a href="https://wg21.link/default.allocator">[default.allocator]</a> as follows:</p>

<blockquote>
<p>
-1- All specializations of the default allocator satisfy the allocator completeness requirements (16.4.4.6.2 <a href="https://wg21.link/allocator.requirements.completeness">[allocator.requirements.completeness]</a>).
</p>
<pre>
namespace std {
  template&lt;class T&gt; class allocator {
  public:
    using value_type = T;
    using size_type = size_t;
    using difference_type = ptrdiff_t;
    using propagate_on_container_move_assignment = true_type;
    <del>using is_always_equal = true_type;</del>
    constexpr allocator() noexcept;
    constexpr allocator(const allocator&amp;) noexcept;
    template&lt;class U&gt; constexpr allocator(const allocator&lt;U&gt;&amp;) noexcept;
    ~allocator();
    allocator&amp; operator=(const allocator&amp;) = default;
    [[nodiscard]] T* allocate(size_t n);
    void deallocate(T* p, size_t n);
  };
}
</pre>
<p>
<ins>-?- <code>allocator_traits&lt;allocator&lt;T&gt;&gt;::is_always_equal::value</code> is <code>true</code> for any <code>T</code>.</ins>
</p>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2019-07 Cologne]</i></p>

<p>
Jonathan provides updated wording.
</p>

<p><i>[2020-10-02; Issue processing telecon: Moved to Tentatively Ready.]</i></p>


<p><i>[2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready &rarr; WP.]</i></p>



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

<ol>
<li><p>Modify 20.2.10 <a href="https://wg21.link/default.allocator">[default.allocator]</a> as follows:</p>

<blockquote>
<p>
-1- All specializations of the default allocator satisfy the allocator completeness requirements (16.4.4.6.2 <a href="https://wg21.link/allocator.requirements.completeness">[allocator.requirements.completeness]</a>).
</p>
<pre>
namespace std {
  template&lt;class T&gt; class allocator {
  public:
    using value_type = T;
    using size_type = size_t;
    using difference_type = ptrdiff_t;
    using propagate_on_container_move_assignment = true_type;
    <del>using is_always_equal = true_type;</del>
    constexpr allocator() noexcept;
    constexpr allocator(const allocator&amp;) noexcept;
    template&lt;class U&gt; constexpr allocator(const allocator&lt;U&gt;&amp;) noexcept;
    ~allocator();
    allocator&amp; operator=(const allocator&amp;) = default;
    [[nodiscard]] T* allocate(size_t n);
    void deallocate(T* p, size_t n);
  };
}
</pre>
<p>
<ins>-?- <code>allocator_traits&lt;allocator&lt;T&gt;&gt;::is_always_equal::value</code> is <code>true</code> for any <code>T</code>.</ins>
</p>
</blockquote>
</li>

<li><p>Add a new subclause in Annex D after 99 [depr.str.strstreams]:</p>

<blockquote>
<p>
<b><ins>D.? The default allocator  [depr.default.allocator]</ins></b>
<p/>
<ins>-?- The following member is defined in addition to those specified in 20.2.10 <a href="https://wg21.link/default.allocator">[default.allocator]</a>:</ins>
</p>
<pre>
<ins>namespace std {
  template &lt;class T&gt; class allocator {
  public:
    using is_always_equal = true_type;
  };
}</ins>
</pre>
</blockquote>
</li>
</ol>





</body>
</html>
