std::is_(nothrow_)convertible
should be reworded to avoid dependence on the return
statementSection: 21.3.7 [meta.rel] Status: New Submitter: Jiang An Opened: 2023-12-18 Last modified: 2023-12-22
Priority: Not Prioritized
View other active issues in [meta.rel].
View all other issues in [meta.rel].
View all issues with New status.
Discussion:
The current specification for std::is_convertible
is sensitive to the requirements for the return
statements. As a result, the requirements were accidentally changed by P0135R1 and then changed back by
CWG issue 2426. The current revision of P2748 also plans to
change the wording for std::is_convertible
to avoid actual behavioral changing.
std::is_convertible
in a such way that is independent to return
statements.
The proposed resolution matches what mainstream implementations do, and should resolve LWG 3400 together.
Proposed resolution:
This wording is relative to N4971.
Modify 21.3.7 [meta.rel] as indicated:
Table 49 — Type relationship predicates [tab:meta.rel] Template Condition Comments […] […] […] template<class From, class To> struct is_convertible;see below From
andTo
shall be
complete types,cv void
, or arrays of
unknown bound. template<class From, class To> struct is_nothrow_convertible;is_convertible_v<From,
is
To>true
andthe
conversion, as defined by
is_convertible
, is known
not to throw any exceptions
either bothFrom
andTo
arecv void
, or the function call
expression used for specifyingis_convertible
is non-throwing (7.6.2.7 [expr.unary.noexcept])From
andTo
shall be
complete types,cv void
, or arrays of
unknown bound.[…] […] […] -5- The predicate condition for a template specialization
is_convertible<From, To>
shall be satisfied if and only ifthe return expression in the following code would be well-formed, including any implicit conversions to the return type of the function:To test() { return declval<From>(); }
[Note 2: This requirement gives well-defined results for reference types, array types, function types, and cv
(?.1) — either both
From
andTo
arecv void
, or(?.2) —
To
is neither array nor function type and the function call expressionconv-dest(declval<From>())
would be well-formed when treated as an unevaluated operand, whereconv-dest
is a hypothetical function declared asvoid conv-dest(To) noexcept;.
void
. — end note] Access checking is performed in a context unrelated toTo
andFrom
. Only the validity of the immediate context of the expression of thereturn statement (8.7.4 [stmt.return])function call expression (7.6.1.3 [expr.call]) (including initialization of thereturnedparameter object or reference) is considered.