Title
Missing constexpr for std::intmax_t math functions in <cinttypes>
Status
c++23
Section
[cinttypes.syn]
Submitter
George Tokmaji

Created on 2022-11-27.00:00:00 last changed 12 months ago

Messages

Date: 2023-02-13.10:17:57

Proposed resolution:

This wording is relative to N4917.

  1. Modify [cinttypes.syn], header <cinttypes> synopsis, as indicated:

    […]
    namespace std {
      using imaxdiv_t = see below;
      
      constexpr intmax_t imaxabs(intmax_t j);
      constexpr imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
      intmax_t strtoimax(const char* nptr, char** endptr, int base);
      uintmax_t strtoumax(const char* nptr, char** endptr, int base);
      intmax_t wcstoimax(const wchar_t* nptr, wchar_t** endptr, int base);
      uintmax_t wcstoumax(const wchar_t* nptr, wchar_t** endptr, int base);
    
      constexpr intmax_t abs(intmax_t);            // optional, see below
      constexpr imaxdiv_t div(intmax_t, intmax_t); // optional, see below
      […]
    }
    […]
    

    -1- The contents and meaning of the header <cinttypes> are the same as the C standard library header <inttypes.h>, with the following changes:

    1. (1.1) — The header <cinttypes> includes the header <cstdint> ([cstdint.syn]) instead of <stdint.h>, and

    2. (1.2) — if and only if the type intmax_t designates an extended integer type ([basic.fundamental]), the following function signatures are added:

      constexpr intmax_t abs(intmax_t);
      constexpr imaxdiv_t div(intmax_t, intmax_t);
      

      which shall have the same semantics as the function signatures constexpr intmax_t imaxabs(intmax_t) and constexpr imaxdiv_t imaxdiv(intmax_t, intmax_t), respectively.

Date: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP. ]

Date: 2023-01-15.00:00:00

[ 2023-01-06; Reflector poll ]

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

Date: 2022-11-27.00:00:00

P0533R9 adds constexpr to math functions in <cmath> and <cstdlib>, which includes std::abs and std::div. This misses the overloads for std::intmax_t in <cinttypes>, as well as std::imaxabs and std::imaxdiv, which seems like an oversight.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 10:17:57adminsetmessages: + msg13364
2023-02-13 10:17:57adminsetstatus: voting -> wp
2023-02-06 15:33:48adminsetstatus: ready -> voting
2023-01-06 14:25:34adminsetmessages: + msg13167
2023-01-06 14:25:34adminsetstatus: new -> ready
2022-11-27 18:24:05adminsetmessages: + msg13120
2022-11-27 00:00:00admincreate