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

Created on 2018-08-09.00:00:00, last changed 2018-08-20.12:41:52.

Messages

Date: 2018-08-20.12:41:52

Proposed resolution:

[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.

  • Modify [concept.convertibleto] as follows:

    template<class From, class To>
      concept ConvertibleTo =
        is_convertible_v<From, To> &&
        requires(From (&f)()) {
          static_cast<To>(f() declval<From>());
        };
    
Date: 2018-08-20.00:00:00

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

Date: 2018-08-09.00:00:00

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

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
2018-08-20 12:41:52adminsetmessages: + msg10044
2018-08-09 00:26:25adminsetmessages: + msg10023
2018-08-09 00:00:00admincreate