<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">

<style type="text/css">

body { color: #000000; background-color: #FFFFFF; }
del { text-decoration: line-through; color: #8B0040; }
ins { text-decoration: underline; color: #005100; }

p.example { margin-left: 2em; }
pre.example { margin-left: 2em; }
div.example { margin-left: 2em; }

code.extract { background-color: #F5F6A2; }
pre.extract { margin-left: 2em; background-color: #F5F6A2;
  border: 1px solid #E1E28E; }

p.function { }
.attribute { margin-left: 2em; }
.attribute dt { float: left; font-style: italic;
  padding-right: 1ex; }
.attribute dd { margin-left: 0em; }

blockquote.std { color: #000000; background-color: #F1F1F1;
  border: 1px solid #D1D1D1;
  padding-left: 0.5em; padding-right: 0.5em; }
blockquote.stddel { text-decoration: line-through;
  color: #000000; background-color: #FFEBFF;
  border: 1px solid #ECD7EC;
  padding-left: 0.5empadding-right: 0.5em; ; }

blockquote.stdins { text-decoration: underline;
  color: #000000; background-color: #C8FFC8;
  border: 1px solid #B3EBB3; padding: 0.5em; }

table { border: 1px solid black; border-spacing: 0px;
  margin-left: auto; margin-right: auto; }
th { text-align: left; vertical-align: top;
  padding-left: 0.8em; border: none; }
td { text-align: left; vertical-align: top;
  padding-left: 0.8em; border: none; }

</style>

<title>A proposal for a type trait to detect narrowing conversions</title>
</head>
<body>
<h1>A proposal for a type trait to detect narrowing conversions</h1>
<p>ISO/IEC JTC1 SC22 WG21 P0870R2 2020-04-06</p>
<p>Project: Programming Language C++</p>
<p>Audience: Study Group 6 (Numerics), Library Evolution Working Group Incubator</p>
<address>Giuseppe D'Angelo, giuseppe.dangelo@kdab.com</address>


<h2>Introduction</h2>

<p>This paper proposes a new type trait for the C++ Standard Library,
<code>is_narrowing_convertible</code>, to detect whether a type is
implictly convertible to another type by going through a narrowing
conversion.</p>

<h2>Changelog</h2>

<ul>
<li>P0870R2
    <ul>
    <li>Incorporated feedback from the LEWGI, EWGI, EWG sessions in Prague.
        In the LEWGI session this proposal was met favourably (2-10-2-1-0).
        EWGI and EWG didn't have any direct feedback
        (and also no particular concerns).</li>
    <li>Elaborated on possible implementations.</li>
    <li>Elaborated more on design decisions, especially regarding whether
        user-defined types should be handled, and whether
        this proposal would constrain core language evolution.
        Unlike R1, we now also include user-defined types in narrow conversion
        sequences (but like R1, we stick to [dcl.init.list] semantics, which
        are not customizable).</li>
    <li>Updated reference to P0608R3.</li>
    <li>Referenced other papers.</li>
    <li>Incorporated the changes to [dcl.init.list] introduced by P1957R2.</li>
    <li>Added SG6 to the target audience.</li>
    <li>Improved spelling.</li>
    </ul>
</li>
<li>P0870R1
    <ul>
    <li>Submitted for the Prague mailing, targeting LEWGI.</li>
    </ul>
</li>
</ul>


<h2>Motivation and Scope</h2>

<p>A <em>narrowing conversion</em> is formally defined by the C++ Standard
in [dcl.init.list], with the intent of forbidding them from
list-initializations.</p> 

<p>It is useful in certain contexts to know whether a conversion between two types
would qualify as a narrowing conversion. For instance, it may be useful to
inhibit (via SFINAE) construction or conversion of "wrapper" types
(like <code>std::variant</code> or <code>std::optional</code>) when
a narrowing conversion is requested.</p>

<p>A use case the author has recently worked on was to prohibit narrowing
conversions when establishing a connection in the Qt framework 
(see [<a href="#QT_NO_NARROWING_CONVERSIONS_IN_CONNECT">Qt</a>]),
with the intent of making the type system more robust. Simplifying,
a connection is established between a <em>signal</em> non-static member function
of an object and a <em>slot</em> non-static member function of another object. 
The signal's and the slot's argument lists must have compatible arguments
for the connection to be established: the signal must have at least as
many arguments as the slot, and the each argument of the signal must be
implictly convertible to the corresponding argument of the slot. In case
of a mismatch, a compile-time error is generated. Bugs have been
observed when connections were successfully established, but a narrowing
conversion (and subsequent loss of data/precision) was happening. Detecting such
narrowing conversions, and making the connection fail for such cases,
would have prevented the bugs.</p>


<h2>Impact On The Standard</h2>

<p>This proposal is a pure library extension.</p>

<p>It proposes changes to an existing header, <code>&lt;type_traits&gt;</code>,
but it does not require changes to any standard classes or functions and
it does not require changes to any of the standard requirement tables.</p>

<p>This proposal does not require any changes in the core language,
and it has been implemented in standard C++.</p>

<p>This proposal does not depend on any other library extensions.</p>

<p>This proposal may help with the implementation of
[<a href="#P0608R3">P0608R3</a>], the adopted resolution for
[<a href="LEWG227">LEWG 227</a>]. In particular, in
[<a href="#P0608R3">P0608R3</a>]'s wording section, the "invented variable
<code>x</code>" is used to detect a narrowing conversion. However, the same
paragraph is also broader than the current proposal, in the sense that it
special-cases boolean conversions [bool.conv], while the current proposal
does not handle them in any special way. The part about boolean conversions
has been anyhow removed by adoping [<a href="#P1957R2">P1957R2</a>].</p>

<p>The just mentioned [<a href="#P1957R2">P1957R2</a>], as a follow up of
[<a href="#P0608R3">P0608R3</a>], made conversions from pointers to
<code>bool</code> narrowing. It was adopted in the Prague meeting,
therefore extending the definition of narrowing conversion in [dcl.init.list].
We do not see this as a problem: we aim to provide a trait to
detect narrowing conversions exactly as specified by the Standard. Should
the specification change, then the trait detection should also change
accordingly; cf. the design decisions below.</p>

<p>This proposal overlaps with [<a href="#P1818R1">P1818R1</a>], a proposal
that aims at introducing a distinction between narrowing and widening conversions.
[<a href="#P1818R1">P1818R1</a>] is much more ambitious than this proposal;
amongst other things, it aims at defining a <code>widening</code> trait.
The wording of [<a href="#P1818R1">P1818R1</a>] is not complete, but we think
that such a trait might simply yield the negation of the trait proposed here;
it would ultimately depend on the exact definition of what constitutes a
"widening conversion". Anyhow, the adoption of [<a href="#P1818R1">P1818R1</a>]
is orthogonal to the present proposal.</p>

<p>[<a href="#P1619R1">P1619R1</a>] and [<a href="#P1998R1">P1998R1</a>] introduce
functions (called respectively <code>can_convert</code> and
<code>is_value_lossless_convertable</code>) that check whether a given value
of an integer type can be represented by another integer type. This is in line
with the spirit of detecting narrowing conversions, namely, preventing loss of
information and/or preventing undefined behavior. While this proposal works on
types, the functions examine specific values; we therefore think that
the proposals are somehow orthogonal to the current proposal.
Moreover, [<a href="#P1619R1">P1619R1</a>] and [<a href="#P1998R1">P1998R1</a>]'s
functions only deal with integer types, while the narrowing definition in
[dcl.init.list] (adopted by this proposal) also deals with floating point and
enumeration types (and, following [<a href="#P1957R2">P1957R2</a>]'s
adoption, also boolean and pointer types).</p>


<h2>Design Decisions</h2>

<p>The most natural place to add the trait presented by this proposal
is the already existing <code>&lt;type_traits&gt;</code> header, which
collects most (if not all) of the type traits available from the Standard Library.</p>

<p>In the <code>&lt;type_traits&gt;</code> header the <code>is_convertible</code>
type trait checks whether a type is implictly convertible to another type.
Building upon this established name, the proposed name for the trait 
described by this proposal shall therefore be <code>is_narrowing_convertible</code>,
with the corresponding <code>is_narrowing_convertible_v</code> type trait helper
variable template.</p>


<h3>Should <code>is_convertible_v&lt;From, To&gt; == true</code> be
a precondition of trying to instantiate 
<code>is_narrowing_convertible&lt;From, To&gt;</code>?</h3>

<p>The author deems this unnecessary. Adding such a precondition would
likely make the usage of the proposed trait more difficult and/or error prone.</p>
<p>As far as the author can see, the precondition is not going to dramatically
simplify the specification for the proposed trait, or its implementation.</p>
<p>In terms of usage: such precondition would force the usage of
<code>std::conjunction</code> (or similar short-circuit behavior)
rather than a simple logical AND to detect whether there is a non-narrowing
conversion between two datatypes, which is what the proposed type trait will be
used for most of the times. In other words, we claim that the most common use
case will be an expression like
<code>is_convertible_v&lt;From, To&gt; &amp;&amp; !is_narrowing_convertible_v&lt;From, To&gt;</code>.
Therefore, we believe that it will be convenient for end users to avoid the
pitfalls related to making <code>is_convertible_v</code> a precondition.</p>


<h3>Should <code>is_narrowing_convertible_v&lt;From, To&gt;</code> yield
<code>true</code> only for the combinations of types listed in [dcl.init.list]?
What about user-defined types?</h3>

<p>The R1 revision of this paper was limiting the possibility for
the trait to yield <code>true</code> if and only if both <code>From</code>
and <code>To</code> were one of the types listed in [dcl.init.list], which
are all builtin types.
Now, while we strongly want the type trait to match the language definition
of narrowing conversion, there are some objections to simply detecting
if we are in one of the those cases.</p>

<p>For instance, should a conversion from <code>const double</code>
to <code>float</code> be considered narrowing or not? If we take the listing
in [dcl.init.list] literally, then the answer would be "no"
(that is, the trait would have to yield <code>false</code>), because
<code>const double</code> is not in the list.
However, this is not really useful, nor expected. If some code checks whether
there is a conversion between two types and the conversion isn't narrowing,
such code could erroneously infer that this is the case between
<code>const double</code> and <code>float</code> and do the conversion.
(This is in spite of the fact that list-initialization would not work,
because <em>there is</em> a narrowing conversion in the conversion sequence).</p>

<p>To elaborate on this last sentence: the definition of list-initialization
in [dcl.init.list] contains several cases where, if a narrowing
conversion takes place, then the program is ill-formed. We believe
that, more than detecting if a given conversion between two types <em>is</em>
a narrowing conversion (as strictly per the definition),
users want to detect if a conversion <em>has</em> a narrowing conversion,
and thus would be forbidden if used in a list-initialization.
As a consequence, we claim that
<code>is_narrowing_convertible_v&lt;const double, float&gt;</code> should
yield <code>true</code>.</p>

<p>This is not simply doable by stripping <code>From</code> and <code>To</code>
of their <em>cv</em>-qualifiers (e.g. by applying <code>std::decay_t</code> on them),
and then checking if the resulting types form a narrowing conversion. One
must also consider all the other cases for conversions, which necessarily
include user-defined types, as they may define implicit conversion operators
that can be used as part of a conversion sequence that also includes a narrowing
conversion. As an example:</p>

<pre class="example">
<code>
struct S { operator double() const; }
S s;
float f1 = s;     // OK
float f2 = { s }; // ERROR: narrowing
</code>
</pre>

<p>We therefore claim that <code>is_narrowing_convertible_v&lt;S, float&gt;</code>
should yield <code>true</code>. A similar example is used in
[<a href="#P0608R3">P0608R3</a>] and
then [<a href="#P1957R2">P1957R2</a>]'s design. Slightly adapted:</p>

<pre class="example">
<code>
struct Bad { operator char const*() &amp;&amp;; };
</code>
</pre>

<p>With the adoption of [<a href="#P1957R2">P1957R2</a>] in the Standard, we
claim that <code>is_narrowing_convertible_v&lt;Bad, bool&gt;</code> should yield
<code>true</code>. For completeness,
<code>is_narrowing_convertible_v&lt;Bad &amp;, bool&gt;</code> should yield
<code>false</code> (there is no conversion), and
<code>is_narrowing_convertible_v&lt;Bad &amp;&amp;, bool&gt;</code> should yield
<code>true</code>.</p>

<p>Note that, although user-defined datatypes are involved, the detection
of whether there is a narrowing conversion sticks to the list of narrowing
conversions in [dcl.list.init], which deals with fixed number of cases:
between certain integer and floating point types; from unscoped enumeration
types to a integer or a floating point type; and from pointer types to boolean.
We are not proposing to allow any customization to these cases (see below).</p>

<h3>Should <code>is_narrowing_convertible_v&lt;From, To&gt;</code> yield
<code>false</code> for boolean conversions [conv.bool]?</h3>

<p>The author deems this to be out of scope for the proposed trait, which should have
only the semantics defined by the language regarding narrowing conversion.
Another trait should be therefore added to detect (implicit) boolean conversions, which,
according to the current wording of [dcl.init.list], are not considered narrowing conversions.
(Note that with the adoption of [<a href="#P1957R2">P1957R2</a>], conversions
from pointer types to boolean are indeed considered narrowing.)</p>
<p>It is the author's opinion that, in general, implicit boolean conversions are undesiderable
for the same reasons that make narrowing conversions unwanted in certain contexts
&mdash; in the sense that a conversion towards bool may discard
important information. However, we recognize the importance of not imbuing a type trait
with extra, not yet well-defined semantics, and therefore we are excluding
boolean conversions from the present proposal.</p>

<h3>Should <code>is_narrowing_convertible&lt;From, To&gt;</code> use
some other semantics than the narrowing defined in [dcl.init.list]?</h3>

<p>Given that narrowing is formally defined in the core language, we are
strongly against deviating from that definition. If anything, proposals
aiming at marking as narrowing certain conversions between user defined types
should also amend the core language definition; the type trait would
still stick to that definition.</p>


<h3>Should specializations of <code>is_narrowing_convertible&lt;From, To&gt;</code> be allowed?</h3>

<p>We believe that specializations of the trait should be forbidden.
This is consistent with the other type traits defined in [meta]
(cf. [meta.rqmts]), and with the fact that the current wording of
[dcl.init.list] defining narrowing conversions does not extend to user-defined
types.</p>

<p>We are aware of broader work happening in the area, such as
[<a href="#P1818R1">P1818R1</a>]. That proposal introduces a keyword to mark
widening conversions, but one may think of an alternative approach where users
are expected to specialize <code>is_narrowing_convertible</code> in order to
mark a conversion as narrowing. In any case, lifting the above limitation on
specializations would always be possible.</p>

<h3>Does providing such a trait make changes to the definition of
"narrowing conversion" harder to land?</h3>

<p>This objection has been raised during the LEWGI meeting in Prague.
The objection is sound, in the sense that a future possible change to
the definition of narrowing conversion will impact user code using the trait.</p>

<p>On the other hand, during the Prague meeting, EWGI and EWG did not raise
this concern regarding this proposal.</p>

<p>First and foremost, we would like to remark that the trait is already
implementable &mdash; and has indeed already been implemented &mdash; using
standard C++ (e.g. via <code>To{std::declval&lt;From&gt;()}</code>, cf. below).
Any change to the definition of narrowing would therefore already be impacting
user code. The impact would likely go beyond type traits / metaprogramming,
since initialization itself would change semantics.
An example of such a change affecting [dcl.init.list] comes from
[<a href="#P1957R2">P1957R2</a>], which has been adopted in Prague. That
adoption changed the semantics of code like <code>bool b = {ptr};</code> (making
it ill-formed; was OK before).</p>

<p>In general, changes to the core language that affected type traits
have already happened. For instance, between C++17 and C++20 the definition
of "aggregate" in [dcl.init.aggr] has been changed, therefore changing the
semantics of the <code>std::is_aggregate</code> type trait.
Similarly, the definitions of "trivial class" and of "trivially copyable class"
in [class.prop] have changed between C++14 and C++17;
meaning that also the type traits <code>std::is_trivial</code> and
<code>std::is_trivially_copy_constructible</code> have changed semantics.</p>

<p>We can therefore reasonably assume that the presence of a trait does not seem
to preclude changes to the core language (or, if such an objection was
raised when proposing these changes to the core language, it was also
disregarded, as the changes did ultimately land).</p>

<p>Finally, it is the author's opinion that code that is using facilities
to detect narrowing conversions would like to stick to the core language
definition. If the definition changes, we foresee that the detection
wants to change too, following the definition. Note that an ad-hoc solution
(rather than a standardized trait) may fall out of sync with the core language
definition, and thus start misdetecting some cases.</p>


<h3>Should there be a matching concept?</h3>

<p>This point was raised during the LEWGI meeting in Prague, and it was
deemed unnecessary at this point, because ultimately this proposal is just
about a type trait. If it will be deemed useful, adding a concept could
always be done at a later time, via another proposal.</p>


<h3>Bikeshedding: <code>is_narrowing_convertible</code> or <code>is_non_narrowing_convertible</code>?</h3>

<p>The Standard Library does not currently have type traits with a negation in their names,
so the current proposal uses a positive tense, although we foresee that the majority
of the usages are going to be about detecting whether there is <em>no</em>
narrowing conversion between two given types. Note that Standard Library
names such as <code>is_nothrow_constructible</code> are not considered
to be negations; the tense is positive, using <code>nothrow</code> as
an adjective/attribute.</p>


<h3>Bikeshedding: <code>is_narrowing_convertible</code> or <code>is_narrowing</code>?</h3>

<p>This paper proposes the former, building on top of the existing <code>is_convertible</code> name;
however, we concede that <code>is_narrowing</code> could lead to cleaner code.
Moreover, at the present time, there should be no ambiguity
over the meaning of <code>is_narrowing</code>: the only usage of "narrowing"
in the Standard is about narrowing conversions.
Nonetheless, it may make sense to future-proof the name proposed here, and
therefore go for the slightly more verbose <code>is_narrowing_convertible</code>.</p>


<h2>Technical Specifications</h2>

<p>The proposed type trait has already been implemented in various codebases using
ad-hoc solutions (depending on the quality of the compiler, etc.), using
standard C++ and without the need of any special compiler hooks.</p>

<p>One possible implementation is to exhaustively check whether a conversion
between two types fall in one of the narrowing cases listed in [dcl.list.init].
This particular implementation has been done in
[<a href="#QT_IS_NARROWING_IMPLEMENTATION">Qt <code>connect()</code></a>];
it has obviously maintenance and complexity shortcomings. The most important
part is:</p>

<pre class="example">
<code>
template&lt;typename From, typename To, typename Enable = void&gt;
struct AreArgumentsNarrowedBase : std::false_type
{
};

template&lt;typename From, typename To&gt;
struct AreArgumentsNarrowedBase&lt;From, To, typename std::enable_if&lt;sizeof(From) &amp;&amp; sizeof(To)&gt;::type&gt;
    : std::integral_constant&lt;bool,
          (std::is_floating_point&lt;From&gt;::value &amp;&amp; std::is_integral&lt;To&gt;::value) ||
          (std::is_floating_point&lt;From&gt;::value &amp;&amp; std::is_floating_point&lt;To&gt;::value &amp;&amp; sizeof(From) &gt; sizeof(To)) ||
          ((std::is_integral&lt;From&gt;::value || std::is_enum&lt;From&gt;::value) &amp;&amp; std::is_floating_point&lt;To&gt;::value) ||
          (std::is_integral&lt;From&gt;::value &amp;&amp; std::is_integral&lt;To&gt;::value
           &amp;&amp; (sizeof(From) &gt; sizeof(To)
               || (std::is_signed&lt;From&gt;::value ? !std::is_signed&lt;To&gt;::value
                   : (std::is_signed&lt;To&gt;::value &amp;&amp; sizeof(From) == sizeof(To))))) ||
          (std::is_enum&lt;From&gt;::value &amp;&amp; std::is_integral&lt;To&gt;::value
           &amp;&amp; (sizeof(From) &gt; sizeof(To)
               || (IsEnumUnderlyingTypeSigned&lt;From&gt;::value ? !std::is_signed&lt;To&gt;::value
                   : (std::is_signed&lt;To&gt;::value &amp;&amp; sizeof(From) == sizeof(To)))))
          &gt;
{
};</code>
</pre>

<p>(Historical note: at the time this implementation was done, the codebase could
only use C++11 features, and some compilers were unable to cope with the
SFINAE solution presented below.).</p>

<p>The Qt implementation strictly checks for the one of narrowing cases listed
in [dcl.init.list], which is not the aim of the current proposal
(cf. design decisions above).
Also, the snippet does not yet implement the change introduced by
[<a href="#P1957R2">P1957R2</a>], showing an inherent limitation to such an
"exhaustive" solution: it may fall out of sync with the core language.</p>

<p>Another, much simpler implementation is to rely on SFINAE around an expression
such as <code>To{std::declval&lt;From&gt;()}</code>. However, this form is also
error-prone: it may accidentally select aggregate initialization for <code>To</code>,
or a constructor taking a <code>std::initializer_list</code>, and so on.
If for any reason these make the expression ill-formed, then the trait is
going to report that there is a narrowing conversion between the types, even
when there actually isn't one (or vice-versa, depending on how one builds
the trait).</p>

<p>[<a href="#P0608R3">P0608R3</a>] uses a clever
workaround to avoid falling into these traps: declaring an array, that is,
building an expression like <code>To t[] = { std::declval&lt;From&gt;() };</code>.
This solution is now used in the Standard (in [variant.ctor] and
[variant.assign]), amongst other things, in order to detect and prevent a
narrowing conversion. The trait that we are proposing could be used to replace
the ad-hoc solution, and clarify the intent of it.</p>

<p>Another possible implementation, that uses the just mentioned workaround,
is the following one (courtesy of Zhihao Yuan; received via private
communication):</p>

<pre class="example">
<code>template&lt;class From, class To&gt;
inline constexpr bool is_narrowing_convertible_v = false;

template&lt;class T, class U&gt;
concept __construct_without_narrowing = requires (U&amp;&amp; x) {
    { std::type_identity_t&lt;T[]&gt;{std::forward&lt;U&gt;(x)} } -&gt; T[1];
};

template&lt;class From, class To&gt; requires std::is_convertible_v&lt;From, To&gt;
inline constexpr bool is_narrowing_convertible_v&lt;From, To&gt; =
    !__construct_without_narrowing&lt;To, From&gt;;
</code>
</pre>

<p>We claim that there is an inherent danger here: it is extremely likely that
non-experts would go for a "na&iuml;ve", wrong solution
(e.g. <code>To{std::declval&lt;From&gt;()}</code>). This further underlines the
necessity of providing detection of narrowing conversions in the Standard Library,
rather than having users reinventing it with ad-hoc solutions.</p>

<h3>Standardese</h3>

<p>In [meta.type.synop], add to the the header synopsis:</p>

<blockquote class="std">
<pre>
<code>
  template &lt;class From, class To&gt; struct is_convertible;
<ins>  template &lt;class From, class To&gt; struct is_narrowing_convertible;</ins>
</code>
</pre>
</blockquote>

<blockquote class="std">
<pre>
<code>
  template &lt;class From, class To&gt;
    inline constexpr bool is_convertible_v = is_convertible&lt;From, To&gt;::value;
<ins>  template &lt;class From, class To&gt;
    inline constexpr bool is_narrowing_convertible_v = is_narrowing_convertible&lt;From, To&gt;::value;</ins>
</code>
</pre>
</blockquote>

<p>In [meta.rel], add a new row to the <em>Type relationship predicates</em> table,
in the same row as for <code>is_convertible</code>:</p>

<blockquote class="std">
<dl class="attribute">
<dt>Template</dt>
<dd>
<p><code>template &lt;class From, class To&gt; struct is_convertible;</code>
<ins><code>template &lt;class From, class To&gt; struct is_narrowing_convertible;</code></ins>
</p></dd>

<dt>Condition</dt>
<dd><p>
<em>see below</em>
</p></dd>

<dt>Comments</dt>
<dd><p><code>From</code> and <code>To</code> shall be complete types,
<em>cv</em> <code>void</code>, or arrays of unknown bound.</p></dd>
</dl>
</blockquote>

<p>Modify paragraph 5 of [meta.rel]:</p>

<blockquote class="std">
<p>5. The predicate condition for a template specialization
<code>is_convertible&lt;From, To&gt;</code><ins> or a template specialization
<code>is_narrowing_convertible&lt;From, To&gt;</code></ins> 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>;
for <code>is_narrowing_convertible&lt;From, To&gt;</code> the conversions shall,
moreover, require a narrowing conversion ([dcl.init.list])</ins>:</p>
<pre>
<code>
To test() {
  return declval&lt;From&gt;();
}
</code>
</pre>
<p>[ <i>Note:</i> This requirement gives well-defined results for reference
types, void types, array types, and function types. <i>&mdash; end note</i> ]
<ins>[ <i>Note:</i> For the purpose of establishing whether the conversion is a
narrowing conversion, the source is never a constant expression.
<i>&mdash; end note</i> ]</ins></p>
</blockquote>

<h2>Acknowledgements</h2>

<p>Thanks to KDAB for supporting this work.</p>
<p>Thanks to Marc Mutz for his feedback and championing this paper in Prague;
to Zhihao Yuan for the discussion and some sample code;
to Andr&eacute; Somers for his feedback.</p>

<h2>References</h2>

<p>[<a name="QT_NO_NARROWING_CONVERSIONS_IN_CONNECT">Qt</a>] Qt version 5.15, <i><a href="https://doc.qt.io/qt-5/qobject.html#QT_NO_NARROWING_CONVERSIONS_IN_CONNECT">QT_NO_NARROWING_CONVERSIONS_IN_CONNECT</a></i>, QObject class documentation</p>
<p>[<a name="QT_IS_NARROWING_IMPLEMENTATION">Qt <code>connect()</code></a>] Qt version 5.15, <i><a href="https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qobjectdefs_impl.h?h=5.15#n288">traits for detecting narrowing conversions</a></i></p>
<p>[<a name="P0608R3">P0608R3</a>] Zhihao Yuan, <i><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0608r3.html">A sane variant converting constructor (LEWG 227)</a></i></p>
<p>[<a name="LEWG227">LEWG 227</a>] Zhihao Yuan, <i><a href="https://issues.isocpp.org/show_bug.cgi?id=227">Bug 227 - variant converting constructor allows unintended conversions</a></i></p>
<p>[<a name="P1957R2">P1957R2</a>] Zhihao Yuan, <i><a href="https://isocpp.org/files/papers/P1957R2.html">Converting from <code>T*</code> to <code>bool</code> should be considered narrowing (re: US 212)</a></i></p>
<p>[<a name="P1818R1">P1818R1</a>] Lawrence Crowl, <i><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1818r1.html">Narrowing and Widening Conversions</a></i></p>
<p>[<a name="P1619R1">P1619R1</a>] Lisa Lippincott, <i><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1619r1.pdf">Functions for Testing Boundary Conditions on Integer Operations</a></i></p>
<p>[<a name="P1998R1">P1998R1</a>] Ryan McDougall, <i><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1998r1.pdf">Simple Facility for Lossless Integer Conversion</a></i></p>

</body>
