Title
The static_cast expression in convertible_to has the wrong operand
Status
c++23
Section
[concept.convertible]
Submitter
Tim Song

Created on 2021-05-26.00:00:00 last changed 12 months ago

Messages

Date: 2021-10-14.09:56:08

Proposed resolution:

This wording is relative to N4885.

  1. Modify [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>());
        };
    
Date: 2021-10-14.00:00:00

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

Date: 2021-06-15.00:00:00

[ 2021-06-07; Reflector poll ]

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

Date: 2021-05-26.00:00:00

The specification of convertible_to implicitly requires static_cast<To>(f()) to be equality-preserving. Under [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.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2021-10-14 09:56:08adminsetmessages: + msg12124
2021-10-14 09:56:08adminsetstatus: voting -> wp
2021-09-29 12:57:28adminsetstatus: ready -> voting
2021-06-07 17:03:22adminsetmessages: + msg11918
2021-06-07 17:03:22adminsetstatus: new -> ready
2021-05-27 17:22:39adminsetmessages: + msg11861
2021-05-26 00:00:00admincreate