Title
ConvertibleTo rejects conversions from array and function types
Status
resolved
Section
[concept.convertible]
Submitter
Casey Carter

Created on 2018-08-09.00:00:00 last changed 41 months ago

Messages

Date: 2020-11-09.22:09:58

Proposed resolution:

This issue is resolved by the resolution of issue 3194.

Date: 2020-11-09.00:00:00

[ 2020-11-09 Resolved for C++20. Status changed: Tentatively Resolved → Resolved. ]

Date: 2018-08-20.00:00:00

[ 2018-08-20 Priority set to 3 after reflector discussion ]

Previous resolution [SUPERSEDED]:

[Drafting Note: I've used declval here, despite that "Concepts mean we never have to use declval again!" because the alternative is less readable:]

requires(add_rvalue_reference_t<From> (&f)()) {
  static_cast<To>(f());
};

This wording is relative to N4762.

  1. Modify [concept.convertible] as follows:

    template<class From, class To>
      concept ConvertibleTo =
        is_convertible_v<From, To> &&
        requires(From (&f)()) {
          static_cast<To>(f() declval<From>());
        };
    
Date: 2019-10-07.03:02:25

In the definition of ConvertibleTo in [concept.convertible]:

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

f is an arbitrary function that returns type From. Since functions cannot return array or function types ([dcl.fct] paragraph 11), ConvertibleTo cannot be satisfied when From is an array or function type regardless of the type of To. This is incompatibility with is_convertible_v was not an intentional design feature, so it should be corrected. (Note that any change made here must take care to avoid breaking the ConvertibleTo<T, void> cases.)

History
Date User Action Args
2020-11-09 22:09:58adminsetmessages: + msg11600
2020-02-13 20:14:26adminsetstatus: new -> resolved
2018-08-20 12:41:52adminsetmessages: + msg10080
2018-08-09 00:26:25adminsetmessages: + msg10059
2018-08-09 00:00:00admincreate