<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3624: Inconsistency of &lt;typeinfo&gt;, &lt;initializer_list&gt;, and 
&lt;compare&gt; in the standard library</title>
<meta property="og:title" content="Issue 3624: Inconsistency of &lt;typeinfo&gt;, &lt;initializer_list&gt;, and 
&lt;compare&gt; in the standard library">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3624.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#New">New</a> status.</em></p>
<h3 id="3624"><a href="lwg-active.html#3624">3624</a>. Inconsistency of <code>&lt;typeinfo&gt;</code>, <code>&lt;initializer_list&gt;</code>, and 
<code>&lt;compare&gt;</code> in the standard library</h3>
<p><b>Section:</b> 17.7 <a href="https://wg21.link/support.rtti">[support.rtti]</a>, 17.11 <a href="https://wg21.link/support.initlist">[support.initlist]</a>, 17.12 <a href="https://wg21.link/cmp">[cmp]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2021-10-23 <b>Last modified:</b> 2022-01-29</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
 Standard library headers <code>&lt;typeinfo&gt;</code>, <code>&lt;initializer_list&gt;</code>, and <code>&lt;compare&gt;</code> 
 are required for some core language features, as specified in 7.6.1.8 <a href="https://wg21.link/expr.typeid">[expr.typeid]</a>/7, 
 9.5.5 <a href="https://wg21.link/dcl.init.list">[dcl.init.list]</a>/2, and 7.6.8 <a href="https://wg21.link/expr.spaceship">[expr.spaceship]</a>/8. In C++11 (via <a href="https://wg21.link/n2930">N2930</a>), 
 every header that has dependency on <code>std::initializer_list</code> is required to include 
 <code>&lt;initializer_list&gt;</code>. The similar requirements are added for <code>operator&lt;=&gt;</code> and 
 <code>&lt;compare&gt;</code> in C++20 (via LWG <a href="lwg-defects.html#3330" title="Include &lt;compare&gt; from most library headers (Status: C++20)">3330</a><sup><a href="https://cplusplus.github.io/LWG/issue3330" title="Latest snapshot">(i)</a></sup>).
<p/>
As N2930 and LWG3330 have been adpoted, IMO there are some inconsistencies in the standard library now:
</p>
<ul>
<li><p>No operation is done for <code>&lt;typeinfo&gt;</code>, although <code>&lt;typeindex&gt;</code> (<code>std::type_index</code>), 
<code>&lt;functional&gt;</code> (<code>std::function</code>, since C++11), and <code>&lt;any&gt;</code> (<code>std::any</code>) 
have dependency on <code>std::type_info</code>;</p></li>
<li><p><code>&lt;iterator&gt;</code> has dependency on <code>std::initializer_list</code> since C++14/LWG <a href="lwg-defects.html#2128" title="Absence of global functions cbegin&#47;cend (Status: C++14)">2128</a><sup><a href="https://cplusplus.github.io/LWG/issue2128" title="Latest snapshot">(i)</a></sup> 
(the <code>std::rbegin</code> overload and its friends), but it is not required to include <code>&lt;initializer_list&gt;</code>;</p></li>
<li><p><code>&lt;stacktrace&gt;</code> is not required to include <code>&lt;compare&gt;</code> while it provides operator 
<code>&lt;=&gt;</code> overloads.</p></li>
</ul>
<p>
The situation may be quite serious for <code>std::type_index</code>. Perhaps no expected operation on <code>std::type_index</code> 
is guaranteed to work when only <code>&lt;typeindex&gt;</code> but not <code>&lt;typeinfo&gt;</code> is included.
<p/>
libc++, libstdc++, and MSVC STL include <code>&lt;typeinfo&gt;</code> and <code>&lt;initializer_list&gt;</code> when 
the required standard interface depends on them. I think we should standardize the existing practice (except 
that <code>&lt;stackstrace&gt;</code> has not been implemented now) to reduce uncertainty for users.
</p>

<p><i>[2021-10-24; Daniel comments]</i></p>

<p>
This issue is related to and depending on LWG <a href="lwg-active.html#3625" title="Should &lt;stacktrace&gt; provide range access function templates? (Status: New)">3625</a><sup><a href="https://cplusplus.github.io/LWG/issue3625" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[2022-01-29; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>



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

<blockquote class="note">
<p>
[<i>Drafting note:</i> The proposed wording below contains one conditional change, it is therefore depending upon
LWG <a href="lwg-active.html#3625" title="Should &lt;stacktrace&gt; provide range access function templates? (Status: New)">3625</a><sup><a href="https://cplusplus.github.io/LWG/issue3625" title="Latest snapshot">(i)</a></sup>.]
</p>
</blockquote>

<ol>
<li><p>Add <code>#include &lt;typeinfo&gt;</code> to 22.7.2 <a href="https://wg21.link/any.synop">[any.synop]</a>, 22.10.2 <a href="https://wg21.link/functional.syn">[functional.syn]</a>, and 
17.7.6 <a href="https://wg21.link/type.index.synopsis">[type.index.synopsis]</a>.</p></li>
<li><p>Add <code>#include &lt;initializer_list&gt;</code> to 24.2 <a href="https://wg21.link/iterator.synopsis">[iterator.synopsis]</a>.</p></li>
<li><p>Add <code>#include &lt;compare&gt;</code> to 19.6.2 <a href="https://wg21.link/stacktrace.syn">[stacktrace.syn]</a>.</p></li>
<li><p>If we decide to add range access function templates (24.7 <a href="https://wg21.link/iterator.range">[iterator.range]</a>) to <code>&lt;stacktrace&gt;</code>, 
we should also add <code>#include &lt;initializer_list&gt;</code> to 19.6.2 <a href="https://wg21.link/stacktrace.syn">[stacktrace.syn]</a>.</p></li>
</ol>





</body>
</html>
