Title
Non-array ssize overload is underconstrained
Status
wp
Section
[iterator.range]
Submitter
Casey Carter

Created on 2019-09-27.00:00:00 last changed 4 months ago

Messages

Date: 2019-11-23.16:16:34

Proposed resolution:

This wording is relative to N4835.

  1. Change Table 52 — "Sign modifications" in [tab:meta.trans.sign] as indicated:

    Table 52 — Sign modifications [tab:meta.trans.sign]
    Template Comments
    template <class T>
    struct make_signed;
    If T names a (possibly cv-qualified) signed integer type ([basic.fundamental]) then
    the member typedef type names the type T; otherwise, if T names a
    (possibly cv-qualified) unsigned integer type then type names the
    corresponding signed integer type, with the same cv-qualifiers as T;
    otherwise, type names the signed integer type with smallest
    rank ([conv.rank]) for which sizeof(T) == sizeof(type), with the same
    cv-qualifiers as T.
    RequiresMandates: T shall beis an (possibly cv-qualified) integral type or enumeration type other than cv but not a bool type.
    template <class T>
    struct make_unsigned;
    If T names a (possibly cv-qualified) unsigned integer type ([basic.fundamental]) then
    the member typedef type names the type T; otherwise, if T names a
    (possibly cv-qualified) signed integer type then type names the
    corresponding unsigned integer type, with the same cv-qualifiers as T;
    otherwise, type names the unsigned integer type with smallest
    rank ([conv.rank]) for which sizeof(T) == sizeof(type), with the same
    cv-qualifiers as T.
    RequiresMandates: T shall beis an (possibly cv-qualified) integral type or enumeration type other than cv but not a bool type.
  2. Change [iterator.range] as indicated:

    template<class C> constexpr auto ssize(const C& c)
      -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
    

    -18- ReturnsEffects: Equivalent to:

    return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>>(c.size());
    

Date: 2019-11-23.00:00:00

[ 2019-11-23 Issue Prioritization ]

Status to Tentatively Ready after five positive votes on the reflector.

Date: 2019-11-15.00:00:00

[ 2019-11-18; Casey comments and improves wording ]

It would be better to provided the Mandates: guarantee in [tab:meta.trans.sign] instead of one special place where the make_signed template is used. The wording below attempts to realize that.

Date: 2019-10-15.00:00:00

[ 2019-10-28; Tim provides improved wording ]

Previous resolution [SUPERSEDED]:

This wording is relative to N4835.

  1. Modify [iterator.range] as indicated:

    template<class C> constexpr auto ssize(const C& c)
      -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
    

    -?- Mandates: decltype(c.size()) is an integral or enumeration type other than bool.

    -18- Returns:

    static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>>(c.size())
    

Date: 2019-11-16.00:00:00

[ 2019-11-16 Issue Prioritization ]

Priority to 3 after reflector discussion.

Previous resolution [SUPERSEDED]:

This wording is relative to N4830.

  1. Modify [iterator.range] as indicated:

    template<class C> constexpr auto ssize(const C& c)
      -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
    

    -?- Mandates: decltype(c.size()) is a (possibly cv-qualified) integral or enumeration type but not a bool type.

    -18- Returns:

    static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>>(c.size())
    

Date: 2019-09-27.00:00:00

The overload of ssize specified in [iterator.range]/18 has no constraints, yet it specializes make_signed_t which has a precondition that its type parameter is an integral type or enumeration but not bool ([meta.trans.sign]). This precondition needs to be propagated to ssize as "Mandates [or Constraints]: decltype(c.size()) [meets the requirements for the type argument to make_signed]". "Mandates" seems to be more in line with LWG guidance since there are no traits nor concepts that observe ssize.

History
Date User Action Args
2020-02-24 16:02:59adminsetstatus: voting -> wp
2020-01-17 04:54:50adminsetstatus: ready -> voting
2019-11-23 16:16:34adminsetmessages: + msg10842
2019-11-23 16:16:34adminsetstatus: new -> ready
2019-11-18 20:24:14adminsetmessages: + msg10827
2019-11-16 13:01:46adminsetmessages: + msg10813
2019-11-16 13:01:46adminsetmessages: + msg10812
2019-10-09 18:10:13adminsetmessages: + msg10690
2019-09-27 00:00:00admincreate