Title
decay-copy should be constrained
Status
c++23
Section
[expos.only.entity]
Submitter
Hui Xie

Created on 2022-06-23.00:00:00 last changed 12 months ago

Messages

Date: 2022-07-25.20:32:58

Proposed resolution:

This wording is relative to N4910.

  1. Modify [expos.only.func] as indicated:

    -2- The following are defined for exposition only to aid in the specification of the library:

    namespace std {
      template<class T> 
        requires convertible_to<T, decay_t<T>>
          constexpr decay_t<T> decay-copy(T&& v)
            noexcept(is_nothrow_convertible_v<T, decay_t<T>>) // exposition only
          { return std::forward<T>(v); }
      […]
    }
    
Date: 2022-07-25.00:00:00

[ 2022-07-25 Approved at July 2022 virtual plenary. Status changed: Ready → WP. ]

Date: 2022-07-15.00:00:00

[ 2022-07-15; LWG telecon: move to Ready ]

Date: 2022-07-15.00:00:00

[ 2022-07-11; Reflector poll ]

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

Date: 2022-07-15.00:00:00

[ 2022-07-08; Reflector poll ]

Set priority to 3 after reflector poll.

Date: 2022-06-23.00:00:00

The spec of views::all [range.all.general] p2 says:

Given a subexpression E, the expression views::all(E) is expression-equivalent to:

  1. (2.1) — decay-copy(E) if the decayed type of E models view.

  2. […]

If E is an lvalue move-only view, according to the spec, views::all(E) would be expression-equivalent to decay-copy(E).

However, [expos.only.func] p2 defines decay-copy as follows

template<class T> constexpr decay_t<T> decay-copy(T&& v)
    noexcept(is_nothrow_convertible_v<T, decay_t<T>>)         // exposition only
  { return std::forward<T>(v); }

It is unconstrained. As a result, for the above example, views::all(E) is a well-formed expression and it would only error on the template instantiation of the function body of decay-copy, because E is an lvalue of move-only type and not copyable.

I think this behaviour is wrong, instead, we should make decay-copy(E) ill-formed if it is not copyable, so that views::all(E) can be SFINAE friendly.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-07-25 20:32:58adminsetmessages: + msg12658
2022-07-25 20:32:58adminsetstatus: ready -> wp
2022-07-25 20:28:19adminsetmessages: + msg12632
2022-07-11 10:09:12adminsetmessages: + msg12579
2022-07-11 10:09:12adminsetstatus: new -> ready
2022-07-08 20:04:38adminsetmessages: + msg12564
2022-06-26 08:58:47adminsetmessages: + msg12537
2022-06-23 00:00:00admincreate