<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 975: is_convertible cannot be instantiated for non-convertible types</title>
<meta property="og:title" content="Issue 975: is_convertible cannot be instantiated for non-convertible types">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue975.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++11">C++11</a> status.</em></p>
<h3 id="975"><a href="lwg-defects.html#975">975</a>. <code>is_convertible</code> cannot be instantiated for non-convertible types</h3>
<p><b>Section:</b> 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2009-01-25 <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#meta.rel">active issues</a> in [meta.rel].</p>
<p><b>View all other</b> <a href="lwg-index.html#meta.rel">issues</a> in [meta.rel].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses UK 206</b></p>

<p>
Related to <a href="lwg-defects.html#1114" title="Type traits underspecified (Status: C++11)">1114</a><sup><a href="https://cplusplus.github.io/LWG/issue1114" title="Latest snapshot">(i)</a></sup>.
</p>

<p>
The current specification of <code>std::is_convertible</code> (reference is draft
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf">N2798</a>)
is basically defined by 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a> p.4:
</p>

<blockquote>
<p>
In order to instantiate the template <code>is_convertible&lt;From,
To&gt;</code>, the following code shall be well formed:
</p>

<blockquote><pre>
template &lt;class T&gt;
  typename add_rvalue_reference&lt;T&gt;::type create();

To test() {
  return create&lt;From&gt;();
}
</pre></blockquote>

<p>
[<i>Note:</i> This requirement gives well defined results for reference
types, void types, array types, and function types. &mdash; <i>end note</i>]
</p>
</blockquote>

<p>
The first sentence can be interpreted, that e.g. the expression
</p>

<blockquote><pre>
std::is_convertible&lt;double, int*&gt;::value
</pre></blockquote>

<p>
is ill-formed because <code>std::is_convertible&lt;double, int*&gt;</code> could not be
instantiated, or in more general terms: The wording requires that
<code>std::is_convertible&lt;X, Y&gt;</code> cannot be instantiated for otherwise valid
argument types <code>X</code> and <code>Y</code> if <code>X</code> is not convertible to <code>Y</code>.
</p>

<p>
This semantic is both unpractical and in contradiction to what the last type
traits paper
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2255.html">N2255</a>
proposed:
</p>

<blockquote>
<p>
If the following <code>test</code> function is well formed code <code>b</code>
is <code>true</code>, else it is <code>false</code>.
</p>

<blockquote><pre>
template &lt;class T&gt;
  typename add_rvalue_reference&lt;T&gt;::type create();

To test() {
  return create&lt;From&gt;();
}
</pre></blockquote>

<p>
[<i>Note:</i> This definition gives well defined results for <code>reference</code>
types, <code>void</code> types, array types, and function types. &mdash; <i>end note</i>]
</p>
</blockquote>

<p><i>[
Post Summit:
]</i></p>


<blockquote>
<p>
Jens: Checking that code is well-formed and then returning <code>true</code>&#47;<code>false</code>
sounds like speculative compilation. John Spicer would really dislike
this. Please find another wording suggesting speculative compilation.
</p>
<p>
Recommend Open.
</p>
</blockquote>

<p><i>[
Post Summit, Howard adds:
]</i></p>


<blockquote>
<p>
John finds the following wording clearer:
</p>
<blockquote>

<table border="1">
<tr>
<th>Template</th><th>Condition</th><th>Comments</th>
</tr>
<tr>
<td><code>template &lt;class From, class To&gt;<br/>struct is_convertible;</code></td>
<td><i>see below</i></td>
<td><code>From</code> and <code>To</code> shall be complete types, arrays of unknown bound,
or (possibly cv-qualified) <code>void</code> types.</td>
</tr>
</table>

<p>
Given the following function prototype:
</p>

<blockquote><pre>
template &lt;class T&gt;
  typename add_rvalue_reference&lt;T&gt;::type create();
</pre></blockquote>

<p>
<code>is_convertible&lt;From, To&gt;::value</code> shall be <code>true</code> if the
return expression in the following code would be well-formed, including
any implicit conversions to the return type of the function, else
<code>is_convertible&lt;From, To&gt;::value</code> shall be <code>false</code>.
</p>

<blockquote><pre>
To test() {
  return create&lt;From&gt;();
}
</pre></blockquote>

</blockquote>

</blockquote>
<p>
<b>Original proposed wording:</b>
</p>
<p>
In 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a>/4 change:
</p>

<blockquote><p>
<del>In order to instantiate the template <code>is_convertible&lt;From, To&gt;</code>, the
following code shall be well formed</del> <ins>If the following code
is well formed <code>is_convertible&lt;From, To&gt;::value</code> is <code>true</code>, otherwise
<code>false</code></ins>:[..]
</p></blockquote>

<p><b>Revision 2</b></p>

<blockquote>

<p>
In 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a> change:
</p>

<blockquote>

<table border="1">
<tr>
<th>Template</th><th>Condition</th><th>Comments</th>
</tr>
<tr><td>...</td><td>...</td><td>...</td></tr>
<tr>
<td><code>template &lt;class From, class To&gt;<br/>struct is_convertible;</code></td>
<td>
<del>The code set out below shall be well formed.</del>
<ins><i>see below</i></ins></td>
<td><code>From</code> and <code>To</code> shall be complete types, arrays of unknown bound,
or (possibly cv-qualified) <code>void</code> types.</td>
</tr>
</table>

<p>
-4- <del>In order to instantiate the template <code>is_convertible&lt;From, To&gt;</code>, the
following code shall be well formed:</del>
<ins>Given the following function prototype:</ins>
</p>

<blockquote><pre>
template &lt;class T&gt; 
  typename add_rvalue_reference&lt;T&gt;::type create();
</pre></blockquote>

<p>
<ins><code>is_convertible&lt;From, To&gt;::value</code> inherits either directly or
indirectly from <code>true_type</code> if the
return expression in the following code would be well-formed, including
any implicit conversions to the return type of the function, else
<code>is_convertible&lt;From, To&gt;::value</code> inherits either directly or
indirectly from <code>false_type</code>.</ins>
</p>

<blockquote><pre>
To test() { 
  return create&lt;From&gt;(); 
}
</pre></blockquote>

<p>
[<i>Note:</i> This requirement gives well defined results for reference types,
void types, array types, and function types. <i>-- end note</i>]
</p>

</blockquote>
</blockquote>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote><p>
We agree with the proposed resolution.
Move to Tentatively Ready.
</p></blockquote>


<p id="res-975"><b>Proposed resolution:</b></p>

<p>
In 21.3.8 <a href="https://wg21.link/meta.rel">[meta.rel]</a> change:
</p>

<blockquote>

<table border="1">
<tr>
<th>Template</th><th>Condition</th><th>Comments</th>
</tr>
<tr><td>...</td><td>...</td><td>...</td></tr>
<tr>
<td><code>template &lt;class From, class To&gt;<br/>struct is_convertible;</code></td>
<td>
<del>The code set out below shall be well formed.</del>
<ins><i>see below</i></ins></td>
<td><code>From</code> and <code>To</code> shall be complete types, arrays of unknown bound,
or (possibly cv-qualified) <code>void</code> types.</td>
</tr>
</table>

<p>
-4- <del>In order to instantiate the template <code>is_convertible&lt;From, To&gt;</code>, the
following code shall be well formed:</del>
<ins>Given the following function prototype:</ins>
</p>

<blockquote><pre>
template &lt;class T&gt; 
  typename add_rvalue_reference&lt;T&gt;::type create();
</pre></blockquote>

<p>
<ins>the predicate condition for a template specialization
<code>is_convertible&lt;From, To&gt;</code> shall be satisfied, if and only
if the return expression in the following code would be well-formed,
including any implicit conversions to the return type of the
function.</ins>
</p>

<blockquote><pre>
To test() { 
  return create&lt;From&gt;(); 
}
</pre></blockquote>

<p>
[<i>Note:</i> This requirement gives well defined results for reference types,
void types, array types, and function types. &mdash; <i>end note</i>]
</p>

</blockquote>





</body>
</html>
