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

3151. ConvertibleTo rejects conversions from array and function types

Section: 18.4.4 [concept.convertible] Status: Resolved Submitter: Casey Carter Opened: 2018-08-09 Last modified: 2020-11-09

Priority: 3

View other active issues in [concept.convertible].

View all other issues in [concept.convertible].

View all issues with Resolved status.

Discussion:

In the definition of ConvertibleTo in 18.4.4 [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 (9.3.4.6 [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.)

[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 18.4.4 [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>());
        };
    

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

Proposed resolution:

This issue is resolved by the resolution of issue 3194(i).