<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2144: Missing noexcept specification in type_index</title>
<meta property="og:title" content="Issue 2144: Missing noexcept specification in type_index">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2144.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++14">C++14</a> status.</em></p>
<h3 id="2144"><a href="lwg-defects.html#2144">2144</a>. Missing <code>noexcept</code> specification in <code>type_index</code></h3>
<p><b>Section:</b> 17.7.7 <a href="https://wg21.link/type.index">[type.index]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2012-03-18 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#type.index">issues</a> in [type.index].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
The class type <code>type_index</code> is a thin wrapper of <code>type_info</code> to
adapt it as a valid associative container element. Similar to <code>type_info</code>, 
all member functions have an effective <code>noexcept(true)</code> specification, with the 
exception of <code>hash_code()</code> and <code>name()</code>. The actual effects of these
functions is a direct call to <code>type_info</code>'s <code>hash_code()</code> and <code>name</code> 
function, but according to 17.7 <a href="https://wg21.link/support.rtti">[support.rtti]</a> these are both <code>noexcept</code>
functions, so there is no reason for not declaring them as <code>noexcept</code>, too. In fact,
one of the suggested changes of the original proposing paper 
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2530.html">N2530</a>
specifically was to ensure that <code>type_info</code> would get a <code>hash_code()</code>
function that guarantees not to throw exceptions (during that time the <code>hash</code>
requirements did not allow to exit with an exception). From this we can conclude that
<code>type_index::hash_code()</code> was intended to be nothrow.
<p/>
It seems both consistent and technically simply to require these functions to be <code>noexcept</code>.
</p>

<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to Tentatively Ready.
</p>

<p><i>[2013-04-20 Bristol]</i></p>




<p id="res-2144"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3376.</p>

<ol>
<li><p>Modify the class <code>type_index</code> synopsis,  [type.index.overview] as indicated:</p>

<blockquote><pre>
namespace std {
  class type_index {
  public:
    type_index(const type_info&amp; rhs) noexcept;
    bool operator==(const type_index&amp; rhs) const noexcept;
    bool operator!=(const type_index&amp; rhs) const noexcept;
    bool operator&lt; (const type_index&amp; rhs) const noexcept;
    bool operator&lt;= (const type_index&amp; rhs) const noexcept;
    bool operator&gt; (const type_index&amp; rhs) const noexcept;
    bool operator&gt;= (const type_index&amp; rhs) const noexcept;
    size_t hash_code() const <ins>noexcept</ins>;
    const char* name() const <ins>noexcept</ins>;
  private:
    const type_info* target; <i>// exposition only</i>
    <i>// Note that the use of a pointer here, rather than a reference,</i>
    <i>// means that the default copy&#47;move constructor and assignment</i>
    <i>// operators will be provided and work as expected.</i>
  };
}
</pre></blockquote>
</li>
</ol>

<ol>
<li><p>Modify the prototype definitions in  [type.index.members] as indicated:</p>

<blockquote><pre>
size_t hash_code() const <ins>noexcept</ins>;
</pre><blockquote>
<p>
-8- <i>Returns</i>: <code>target->hash_code()</code>
</p>
</blockquote>
<pre>
const char* name() const <ins>noexcept</ins>;
</pre><blockquote>
<p>
-9- <i>Returns</i>: <code>target->name()</code>
</p>
</blockquote>
</blockquote>

</li>
</ol>






</body>
</html>
