<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2560: is_constructible underspecified when applied to a function type</title>
<meta property="og:title" content="Issue 2560: is_constructible underspecified when applied to a function type">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2560.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++17">C++17</a> status.</em></p>
<h3 id="2560"><a href="lwg-defects.html#2560">2560</a>. <code>is_constructible</code> underspecified when applied to a function type</h3>
<p><b>Section:</b> 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2015-11-14 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>0
</p>
<p><b>View other</b> <a href="lwg-index-open.html#meta.unary.prop">active issues</a> in [meta.unary.prop].</p>
<p><b>View all other</b> <a href="lwg-index.html#meta.unary.prop">issues</a> in [meta.unary.prop].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
What is <code>is_constructible&lt;void()&gt;::value</code>? Per 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a> p8:
</p>
<blockquote>
<p>
The predicate condition for a template specialization <code>is_constructible&lt;T, Args...&gt;</code> shall be satisfied if
and only if the following variable definition would be well-formed for some invented variable <code>t</code>:
</p>
<blockquote><pre>
T t(declval&lt;Args&gt;()...);
</pre></blockquote>
<p>
[<i>Note</i>: These tokens are never interpreted as a function declaration. &mdash; <i>end note</i>]
</p>
</blockquote>
<p>
The problem here is that substituting in <code>T</code> as a function type doesn't give a variable definition that's not well-formed 
(by 3.68 <a href="https://wg21.link/defns.well.formed">[defns.well.formed]</a>, well-formed means that it doesn't violate any syntactic or diagnosable semantic rules, and 
it does not). Instead, it gives a logical absurdity: this wording forces us to imagine a variable of function type, which contradicts 
the definition of "variable" in 3/6, but does so without violating any diagnosable language rule. So presumably the result must 
be undefined behavior.
<p/>
It seems that we need an explicit rule requiring <code>T</code> to be an object or reference type.
<p/>
<b>Daniel:</b>
<p/>
As one of the authors of <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3142.html">N3142</a> I would like
to express that at least according to my mental model the intention for this trait was to be well-defined for <code>T</code> being
a function type with the result of <code>false</code> regardless of what the other type arguments are. It would seem like a very 
unfortunate and unnecessary complication to keep the result as being undefined. First, this result value is symmetric to
the result of <code>is_destructible&lt;T&gt;::value</code> (where the word covers function types explicitly). Second, if such a
resolution would be applied to the working paper, it wouldn't break existing implementations. I have tested clang 3.8.0,
gcc 5.x until gcc 6.0, and Visual Studio 2015, all of these implementations evaluate <code>is_constructible&lt;void()&gt;::value</code>
to <code>false</code>. 
</p>

<p><i>[2016-02, Issues Telecon]</i></p>

<p>
P0; move to Tentatively Ready.
</p>


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

<ol>
<li><p>Change 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a>, Table 49 &mdash; "Type property predicates", as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 49 &mdash; Type property predicates</caption>
<tr>
<th align="center">Template</th>
<th align="center">Condition</th>
<th align="center">Preconditions</th>
</tr>

<tr>
<td colspan="3" align="center">
<code>&hellip;</code>
</td>
</tr>

<tr>
<td>
<code>template &lt;class T, class... Args&gt;<br/>
struct is_constructible;</code>
</td>

<td>
<ins>For a function type <code>T</code>,<br/> 
<code>is_constructible&lt;T, Args...&gt;::value</code><br/>
is <code>false</code>, otherwise</ins> <i>see below</i>
</td>

<td align="center">
<code>T</code> and all types in the<br/>
parameter pack <code>Args</code> shall<br/>
be complete types,<br/>
(possibly <i>cv</i>-qualified)<br/>
<code>void</code>, or arrays of<br/>
unknown bound.
</td>
</tr>

<tr>
<td colspan="3" align="center">
<code>&hellip;</code>
</td>
</tr>

</table>
</blockquote>
</li>
</ol>





</body>
</html>
