This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

3557. The static_cast expression in convertible_to has the wrong operand

Section: 18.4.4 [concept.convertible] Status: WP Submitter: Tim Song Opened: 2021-05-26 Last modified: 2021-10-17

Priority: Not Prioritized

View other active issues in [concept.convertible].

View all other issues in [concept.convertible].

View all issues with WP status.

Discussion:

The specification of convertible_to implicitly requires static_cast<To>(f()) to be equality-preserving. Under 18.2 [concepts.equality] p1, the operand of this expression is f, but what we really want is for f() to be treated as the operand. We should just use declval (which is treated specially by the definition of "operand" for this purpose) instead of reinventing the wheel.

[2021-06-07; Reflector poll]

Set status to Tentatively Ready after nine votes in favour during reflector poll.

[2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4885.

  1. Modify 18.4.4 [concept.convertible] as indicated:

    template<class From, class To>
      concept convertible_to =
        is_convertible_v<From, To> &&
        requires(add_rvalue_reference_t<From> (&f)()) {
          static_cast<To>(fdeclval<From>());
        };