Skip to content

Commit 6eca556

Browse files
committed
New issue from Jiang An: "std::is_(nothrow_)convertible should be reworded to avoid dependence on the return statement"
1 parent f1f8275 commit 6eca556

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

xml/issue4028.xml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4028" status="New">
5+
<title><tt>std::is_(nothrow_)convertible</tt> should be reworded to avoid dependence on the <tt>return</tt> statement</title>
6+
<section><sref ref="[meta.rel]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>18 Dec 2023</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
The current specification for <tt>std::is_convertible</tt> is sensitive to the requirements for the <tt>return</tt>
14+
statements. As a result, the requirements were accidentally changed by <paper num="P0135R1"/> and then changed back by
15+
CWG issue <a href="https://wg21.link/cwg2426">2426</a>. The current revision of <paper num="P2748"/> also plans to
16+
change the wording for <tt>std::is_convertible</tt> to avoid actual behavioral changing.
17+
<p/>
18+
IMO it's better to specify <tt>std::is_convertible</tt> in a such way that is independent to <tt>return</tt> statements.
19+
The proposed resolution matches what mainstream implementations do, and should resolve LWG <iref ref="3400"/> together.
20+
</p>
21+
</discussion>
22+
23+
<resolution>
24+
<p>
25+
This wording is relative to <paper num="N4971"/>.
26+
</p>
27+
28+
<ol>
29+
30+
<li><p>Modify <sref ref="[meta.rel]"/> as indicated:</p>
31+
32+
<blockquote>
33+
<table border="1">
34+
<caption>Table 49 &mdash; Type relationship predicates [tab:meta.rel]</caption>
35+
<tr style="text-align:center">
36+
<th>Template</th>
37+
<th>Condition</th>
38+
<th>Comments</th>
39+
</tr>
40+
<tr>
41+
<td>[&hellip;]</td>
42+
<td>[&hellip;]</td>
43+
<td>[&hellip;]</td>
44+
</tr>
45+
<tr>
46+
<td>
47+
<pre>
48+
template&lt;class From, class To&gt;
49+
struct is_convertible;
50+
</pre>
51+
</td>
52+
<td><i>see below</i></td>
53+
<td>
54+
<tt>From</tt> and <tt>To</tt> shall be<br/>
55+
complete types, <tt><i>cv</i> void</tt>, or arrays of<br/>
56+
unknown bound.
57+
</td>
58+
</tr>
59+
<tr>
60+
<td>
61+
<pre>
62+
template&lt;class From, class To&gt;
63+
struct is_nothrow_convertible;
64+
</pre>
65+
</td>
66+
<td>
67+
<tt>is_convertible_v&lt;From,<br/>
68+
To&gt;</tt> is <tt>true</tt> and <del>the</del><br/>
69+
<del>conversion, as defined by</del><br/>
70+
<del><tt>is_convertible</tt>, is known</del><br/>
71+
<del>not to throw any exceptions</del><br/>
72+
<ins>either both <tt>From</tt> and <tt>To</tt><br/>
73+
are <tt><i>cv</i> void</tt>, or the function call<br/>
74+
expression used for specifying <tt>is_convertible</tt><br/>
75+
is non-throwing</ins> (<sref ref="[expr.unary.noexcept]"/>)
76+
</td>
77+
<td>
78+
<tt>From</tt> and <tt>To</tt> shall be<br/>
79+
complete types, <tt><i>cv</i> void</tt>, or arrays of<br/>
80+
unknown bound.
81+
</td>
82+
</tr>
83+
<tr>
84+
<td>[&hellip;]</td>
85+
<td>[&hellip;]</td>
86+
<td>[&hellip;]</td>
87+
</tr>
88+
</table>
89+
90+
<p>
91+
-5- The predicate condition for a template specialization <tt>is_convertible&lt;From, To&gt;</tt>
92+
shall be satisfied if and only if <del>the return expression in the following code would be well-formed,
93+
including any implicit conversions to the return type of the function:</del>
94+
</p>
95+
<blockquote><pre>
96+
<del>To test() {
97+
return declval&lt;From&gt;();
98+
}</del>
99+
</pre></blockquote>
100+
<p>
101+
<ol style="list-style-type: none">
102+
<li><p><ins>(?.1) &mdash; either both <tt>From</tt> and <tt>To</tt> are <tt><i>cv</i> void</tt>, or</ins></p></li>
103+
<li><p><ins>(?.2) &mdash; <tt>To</tt> is neither array nor function type and the function call expression
104+
<tt><i>conv-dest</i>(declval&lt;From&gt;())</tt> would be well-formed when treated as an unevaluated operand,
105+
where <tt><i>conv-dest</i></tt> is a hypothetical function declared as</ins></p>
106+
<blockquote><pre>
107+
<ins>void <i>conv-dest</i>(To) noexcept;</ins>
108+
</pre></blockquote>
109+
<p>
110+
<ins>.</ins>
111+
</p>
112+
</li>
113+
</ol>
114+
<p/>
115+
[<i>Note 2</i>: This requirement gives well-defined results for reference types, array types, function types,
116+
and <i>cv</i> <tt>void</tt>. &mdash; <i>end note</i>]
117+
<p/>
118+
Access checking is performed in a context unrelated to <tt>To</tt> and <tt>From</tt>. Only the validity of the
119+
immediate context of the expression of the <del>return statement (<sref ref="[stmt.return]"/>)</del>
120+
<ins>function call expression (<sref ref="[expr.call]"/>)</ins> (including initialization of the
121+
<del>returned</del><ins>parameter</ins> object or reference) is considered.
122+
</p>
123+
</blockquote>
124+
</li>
125+
126+
</ol>
127+
128+
129+
</resolution>
130+
131+
</issue>

0 commit comments

Comments
 (0)