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

3834. Missing constexpr for std::intmax_t math functions in <cinttypes>

Section: 31.13.2 [cinttypes.syn] Status: C++23 Submitter: George Tokmaji Opened: 2022-11-27 Last modified: 2023-11-22

Priority: Not Prioritized

View all issues with C++23 status.

Discussion:

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.

[2023-01-06; Reflector poll]

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

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

Proposed resolution:

This wording is relative to N4917.

  1. Modify 31.13.2 [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> (17.4.1 [cstdint.syn]) instead of <stdint.h>, and

    2. (1.2) — if and only if the type intmax_t designates an extended integer type (6.8.2 [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.